myer0244
04-06-2009, 10:38 AM
Hello folks,
I am somewhat new to writing in xcode/obj-c.
I am trying to re-write one of my programs I had written with C# onto the mac platform. I have figured most of it out now, but there is one little piece that I cannot seem to overcome that I thought you all might be able to help me out with.
What I am trying to do is send a string of Hex data to a serial port usb dongle(rs232) I have figured a way to connect to the RS232 port and am able to send data to it already. My problem is converting the data to what the device on the other end of the rs232 cable can read.
Here is a snippet of my C# code:
private byte[] HexStringToByteArray(string s)
{
s = s.Replace(" ", "");
byte[] buffer = new byte[s.Length / 2];
for (int i = 0; i < s.Length; i += 2)
buffer[i / 2] = (byte)Convert.ToByte(s.Substring(i, 2), 16);
return buffer;
}
This converts a string of Hex data with or without spaces into an array of bytes in C#. The data is then sent out the designated communications port which the device can read.
My question is:
Is there a method to do this using Xcode/Obj-C? I have dug through the internet for about a week now and have not been able to find anything. Only converting bytes to hex which is not what i need. Anybody have any ideas?
Any help is appreciated!
I am somewhat new to writing in xcode/obj-c.
I am trying to re-write one of my programs I had written with C# onto the mac platform. I have figured most of it out now, but there is one little piece that I cannot seem to overcome that I thought you all might be able to help me out with.
What I am trying to do is send a string of Hex data to a serial port usb dongle(rs232) I have figured a way to connect to the RS232 port and am able to send data to it already. My problem is converting the data to what the device on the other end of the rs232 cable can read.
Here is a snippet of my C# code:
private byte[] HexStringToByteArray(string s)
{
s = s.Replace(" ", "");
byte[] buffer = new byte[s.Length / 2];
for (int i = 0; i < s.Length; i += 2)
buffer[i / 2] = (byte)Convert.ToByte(s.Substring(i, 2), 16);
return buffer;
}
This converts a string of Hex data with or without spaces into an array of bytes in C#. The data is then sent out the designated communications port which the device can read.
My question is:
Is there a method to do this using Xcode/Obj-C? I have dug through the internet for about a week now and have not been able to find anything. Only converting bytes to hex which is not what i need. Anybody have any ideas?
Any help is appreciated!