Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i'm tryint to communicate with a relay box connected with a serial cable. you send a command of N1 to open the first relay, N2 to open the second, etc... i've tested it with hyperterminal and it works fine. i'm usin a c++ mfc app in vs.net03. i've just added code to my program, if there are any settings that i have to set, then i don't know about them. i'm using the CSerial class
http://www.codeproject.com/system/serial.asp
portName and relay are both CStrings. anyone know what's wrong??CSerial link;
link.Open(portName); //either COM1 or COM2
//set the port settings
link.Setup(CSerial::EBaudrate(9600), CSerial::EDataBits(,
CSerial::EParity(NOPARITY), CSerial::EStopBits(ONESTOPBIT));if(relay[0]=='1')
relay.Delete(0,1);
link.Write(relay); //writing "N1" or whatever
//find time for pump to stay open
runtime=drinklist[num].amount[x]*MULTIPLIER;
Sleep(runtime*1000);
relay.Delete(0,1);
relay.Insert(0,"F");
link.Write(relay);
link.Close();
thanx

Heyu oh4u2nv, just checking out the board. The only thing I can think of that would mess up your program is that you do not specify a null terminated string. For example in the hello world example giving for CSerial class, he passes:
serial.Write("Hello world\n");
perhaps try appending a \n to the end of your string before sending and see if that changes anything (I had had a similiar problem using a different serial class (WSC4C) in that if the string was not null terminated the receiving side never new when to read/empty the buffer.
(Oh yeah, and since it's MFC if the \n doesn't work you might want to quickly try adding \r\n since this is apparently what it uses at least for socket sending).
Good luck.

![]() |
text in table wraps by it...
|
DarkBASIC RealBASIC
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |