Computing.Net > Forums > Programming > serial communication in mfc

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

serial communication in mfc

Reply to Message Icon

Name: oh4u2nv
Date: December 18, 2003 at 11:36:34 Pacific
OS: winxp
CPU/Ram: 512
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Daemon Rose
Date: December 24, 2003 at 05:46:28 Pacific
Reply:

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.


0
Reply to Message Icon

Related Posts

See More


text in table wraps by it... DarkBASIC RealBASIC



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: serial communication in mfc

Serial Communication in C++ www.computing.net/answers/programming/serial-communication-in-c/4866.html

Input from Serial Port in Java/C++ www.computing.net/answers/programming/input-from-serial-port-in-javac/11868.html

Visual C++ for serial communication www.computing.net/answers/programming/visual-c-for-serial-communication/5188.html