Communicating through omron hostlink

G

Thread Starter

g

i need some sample code for communicating through omron hostlink protocol (preffered in Delphi).
i have read all books i've found about. i already taught myself to build command for hostlink protocol, but when i send it to port no results occured.
i've tried to use directly connected to COM hyperterminal and also tried to build an terminal program using Varian Async 32 module but no result.
any help for Active X component (free ;-) ) or sample code please ?

g.
 
did you appended CRC and '*' too to the command you built?

a simple sample code in C++ what i've used:


///
string doCRC(string str)
{
WORD cs = 0;
for( const char *p=str.c_str(); *p; p++)
cs ^= *p;
ostringstream ss;
ss << setfill('0') << uppercase << hex << setw(2) << cs;
return ss.str();
}

// this sends the command

string Send(string Cmd, int Node_)
{
ostringstream ss;
ss << '@' << setfill('0') << setw(2) << Node_ << Cmd;
ss << doCRC(ss.str()) << "*\x0D";
WriteToPort((char*)ss.str().c_str(), ss.str().length());

//wait for response in some loop here
//...
//

string resp = ReadPort();
resp.erase(resp.size()-1,1); // cut off '*'
if(resp.length() > 3) {
//validate checksum
string ocrc = resp.substr(resp.size()-2); // original crc
string crc = CalcCRC(resp.erase(resp.size()-2, 2)); // calculated
if(crc != ocrc) {
// transmission error!
}
return resp.erase(0,3); //cut off beginning @xx and return as response
}
}
return ""; // no response
}

/////////

rgds, bonker
 
Top