i'm using serial.cpp code arduino's website.
what i'm doing right using r220hprs relay switch. problem sample codes in vb , i'm using c++. so, read through manual , found sending ascii 254 , ascii 1 turn relay 1 switch on
vb example
mscomm1.output = chr$(254) 'enter command mode mscomm1.output = chr$(1) 'turn on relay 1
then found serial.cpp arduino's website , decided try using it. , when did, got connect device (or said did when ran program), don't know how send ascii 254 , ascii 1
here's code serial.cpp
bool serial::writedata(char *buffer, unsigned int nbchar) { dword bytessend; //try write buffer on serial port if(!writefile(this->hserial, (void *)buffer, nbchar, &bytessend, 0)) { //in case don't work comm error , return false clearcommerror(this->hserial, &this->errors, &this->status); return false; } else return true; }
main
int _tmain(int argc, _tchar* argv[]) { printf("welcome serial test app!\n\n"); serial* sp = new serial("\\\\.\\com3"); // adjust needed if (sp->isconnected()) printf("we're connected"); while(sp->isconnected()) { char *chr0 = "254"; sp->writedata(chr0, 1); sp->writedata(chr0, 1); sleep(500); } return 0; }
i know chr0 = "254" not ascii, don't have idea how send ascii 254 , ascii 1.
to send single char
value 245, need make char:
char chr0 = 254; sp->writedata(&chr0, 1);
Comments
Post a Comment