I have to send byte values to a C dll that is expecting char* which is apparently not allowed. Did some searching and I'm supposed to replace the char* with [MarshalAs(UnmanagedType.LPStr)] string myBytes
That's all fine but I'm trying to figure out how to create a string from a byte array in a way that each character in the string represents the original byte value rather than a three digit string of the decimal value. e.g. If I convert 0xFF to string I end up with a string of "255".
It's probably just that I'm up way too late (had a nap in the afternoon) but I just can't wrap my head around it. Anyway, here's the actual code I'm trying to sort out.
So how would I make an appropriate string out of two bytes like 0x84 and 0xB8?
That's all fine but I'm trying to figure out how to create a string from a byte array in a way that each character in the string represents the original byte value rather than a three digit string of the decimal value. e.g. If I convert 0xFF to string I end up with a string of "255".
It's probably just that I'm up way too late (had a nap in the afternoon) but I just can't wrap my head around it. Anyway, here's the actual code I'm trying to sort out.
C#:
[DllImport("libpigpiod_if.so", EntryPoint = "i2c_write_device")] //This is an example of how to call a method / function in a c library from c#
public static extern int i2c_write_device(uint handle, [MarshalAs(UnmanagedType.LPStr)] string buf, uint count);
The original C definition is
int i2c_read_device(unsigned handle, char *buf, unsigned count);
So how would I make an appropriate string out of two bytes like 0x84 and 0xB8?