Hi~
I want to connect the Arduino (or maybe Wiring since it has 2 serial ports) to this Gamoto motor controller:
http://www.gamatronix.com/product_info.php/products_id/28
There is C++ example code near the bottom of the page (too long to post here but here's a link:)
http://www.gamatronix.com/gamoto/software/GamotoObject.zip
I am almost able to compile this code as a library in Arduino/Wiring - except the example code has a dependency (as an #include) on some C++ WIN serial stuff that I don't want to use. It basically sets up a COM port on a Windows machine, etc.
The Arduino compile is failing on these routines (below) - which essentially do what Serial.read and Serial.print do. Can I create a Serial object in this code through a '#include "WProgram.h"?
Oh - while I am here: this Gamoto code uses DWORD - I looked it up and that seems eq. to a long. Is that correct?
Thanks for any tips! I'll be tinkering away at this but I figured I ask before I burn too much time.
--Roy
UINT WriteBytes(unsigned char * lpBuf, DWORD dwToWrite)
{
// Writes some bytes out the COM port. Returns 0 if successful, error code of LastError if not
// lpBuf = pointer to array of bytes
// dwToWrite = how many bytes to write
DWORD dwWritten;
//
// issue write
//
if (!WriteFile(COMDEV(TTYInfo), lpBuf, dwToWrite, &dwWritten, NULL))
return GetLastError();
else
return (0);
}
UINT WriteString(char* wstr){
//writes a zero-terminated string to the com port
return (WriteBytes((unsigned char*)wstr,(DWORD)strlen(wstr)));
}
UINT ReadByte(unsigned char* lpBuf,DWORD * dwRead) {
// Read byte from the COM port
// Returns 0 if successful
// dwRead = number bytes that were actually read, this is set by the ReadFile routine
// for this function, dwRead will be either 0 or 1
// UINT result; //return value from this function (0 = OK, else error code)
if (!ReadFile(COMDEV(TTYInfo), lpBuf, 1, dwRead, NULL))
return GetLastError();
else return 0;
}
UINT ReadBytes(unsigned char* lpBuf,DWORD * dwRead,int maxsize) {
// Read multiple bytes from the COM port
// Returns 0 if successful
// dwRead = number bytes that were actually read, this is set by the ReadFile routine
// maxsize = maximum number of bytes to read (MUST be <= size of lpBuf passed in)
// NOTE: buffer (lpBuf) is not returned with a zero terminator (not a string)
// UINT result; //return value from this function (0 = OK, else error code)
if (!ReadFile(COMDEV(TTYInfo), lpBuf, maxsize, dwRead, NULL))
return GetLastError();
else return 0;
}