Prev: Microsoft compiler
Next: global fit
From: mathew on 24 May 2010 06:14 I am trying to control a device via serial port from Matlab.In order to do that I need to send HEX numbers (one number at a time as a byte) via COM port. I am able to open and close the port, successfully. But I am yet to succeed in sending a hex number. For example, to send 3A, I am trying the following datatosend='58'; % 58 is the decimal equivalent fprintf(s,'%X', datatosend); Instead of 3A, Matlab is writing 35 to the port (device has the possibility to display the 'command' it receives over the COM port). Can some one advice, what could be wrong here OR possible solutions to this issue? Thanks, in advance.
From: Rune Allnor on 24 May 2010 10:38 On 24 Mai, 16:14, "mathew(a)upb" <mathewgeorge...(a)hotmail.com> wrote: > I am trying to control a device via serial port from Matlab.In order to do that I need to send HEX numbers (one number at a time as a byte) via COM port. I am able to open and close the port, successfully. But I am yet to succeed in sending a hex number. > > For example, to send 3A, I am trying the following > > datatosend='58'; % 58 is the decimal equivalent > fprintf(s,'%X', datatosend); > > Instead of 3A, Matlab is writing 35 to the port (device has the possibility to display the 'command' it receives over the COM port). > > Can some one advice, what could be wrong here OR possible solutions to this issue? > > Thanks, in advance. >> datatosend=58; % 58 is the decimal equivalent >> fprintf('%X', datatosend); 3A>> Rune
From: Walter Roberson on 24 May 2010 10:45 mathew(a)upb wrote: > I am trying to control a device via serial port from Matlab. In order to do that I need to send HEX numbers (one number at a time as a byte) via COM port. I still do not know what that means, to send a "hex number", unless it means to send the character representation of the first nibble and the character representation of the second nibble. Are you *certain* that you really need to send hex and not bytes of equivalent value? fwrite(s, char(hex2num('3A')), '*char')
From: us on 24 May 2010 10:47 "mathew(a)upb" <mathewgeorge100(a)hotmail.com> wrote in message <1673839772.214575.1274710517166.JavaMail.root(a)gallium.mathforum.org>... > I am trying to control a device via serial port from Matlab.In order to do that I need to send HEX numbers (one number at a time as a byte) via COM port. I am able to open and close the port, successfully. But I am yet to succeed in sending a hex number. > > For example, to send 3A, I am trying the following > > datatosend='58'; % 58 is the decimal equivalent > fprintf(s,'%X', datatosend); > > Instead of 3A, Matlab is writing 35 to the port (device has the possibility to display the 'command' it receives over the COM port). > > Can some one advice, what could be wrong here OR possible solutions to this issue? > > Thanks, in advance. why use a CHAR... d=58; sprintf('%X',d) % ans = 3A us
From: mathew on 10 Jun 2010 12:01 Thank you all, for the inputs. The issue was solved by sending binary equivalents of the hex codes via serial port using.
|
Pages: 1 Prev: Microsoft compiler Next: global fit |