The errors/warnings you showed are NOT the "compile" ones. They are runtime errors/warnings.
Printable View
yes, I'm sorry
The connection between bluetooth device and PC is working.
In the code of http://www.naughter.com/serialport.html there is the app.cpp code. When it runs the port is opened and the connection is made but after some seconds appears this error:
CSerialPort::Write, Failed in call to WriteFile, Error:997
This is a part of app.cpp code:
PHP Code:
CSerialPort port2;
port2.Open(6, 9600, CSerialPort::NoParity, 8, CSerialPort::OneStopBit, CSerialPort::XonXoffFlowControl, TRUE);
CEvent event(FALSE, TRUE);
OVERLAPPED overlapped;
memset(&overlapped, 0, sizeof(overlapped));
overlapped.hEvent = event;
try
{
port2.Write(pBuf, 10000, overlapped);
}
catch(CSerialException* pEx)
{
if (pEx->m_dwError == ERROR_IO_PENDING)
{
DWORD dwBytesTransferred = 0;
port2.GetOverlappedResult(overlapped, dwBytesTransferred, TRUE);
pEx->Delete();
}
else
{
DWORD dwError = pEx->m_dwError;
Instead this is the part of code od SerialPort.cpp of error message:
PHP Code:
void CSerialPort::Write(const void* lpBuf, DWORD dwCount, OVERLAPPED& overlapped, DWORD* pBytesWritten)
{
//Validate our parameters
ASSERT(IsOpen());
DWORD dwBytesWritten = 0;
BOOL bSuccess = WriteFile(m_hComm, lpBuf, dwCount, &dwBytesWritten, &overlapped);
if (!bSuccess)
{
DWORD dwLastError = GetLastError();
TRACE(_T("CSerialPort::Write, Failed in call to WriteFile, Error:%d\n"), dwLastError);
ThrowSerialException(dwLastError);
}
ERROR_IO_PENDING (error 997) just means that Write operation is not completed yet! From MSDN:Please, read about Serial Communications in MSDN:Quote:
... GetLastError function returns ERROR_IO_PENDING. This allows the calling process to continue processing while the write operation is being completed. The event specified in the OVERLAPPED structure is set to the signaled state upon completion of the write operation.
http://msdn.microsoft.com/en-us/library/ff802693.aspx
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
thank you very much Victor for your help! I'm a new programmer, but i'm improving and the communication between PC and device has been established also with C++ language. I discovered that I have problems with writefile becouse the device bluetooth use Cobs codification and now I'm trying to understand the following Cobs code:
this code is used to Cobs codification, but I don't understand how i can use it to codify my array of bytes.PHP Code:
/*
* StuffData byte stuffs "length" bytes of
* data at the location pointed to by "ptr",
* writing the output to the location pointed
* to by "dst".
*/
#define FinishBlock(X) \
(*code_ptr = (X), \
code_ptr = dst++, \
code = 0x01)
void StuffData(const unsigned char *ptr,
unsigned long length, unsigned char *dst)
{
const unsigned char *end = ptr + length;
unsigned char *code_ptr = dst++;
unsigned char code = 0x01;
while (ptr < end)
{
if (*ptr == 0) FinishBlock(code);
else
{
*dst++ = *ptr;
code++;
if (code == 0xFF) FinishBlock(code);
}
ptr++;
}
FinishBlock(code);
}
Sorry, but I have no idea what these FinishBlock macro and StuffData function are for and where they come from... :confused:
BTW, you should use Code tags (using # toolbar button) rather than PHP or HTML ones.
Besides, your code is very bad formatted: messed indentations and more than one statement on the same line make reading/understanding this code very difficult!
I copied that from here: http://www.stuartcheshire.org/papers/COBSforSIGCOMM/ (at the end of page)
Well, then try to encode your byte sequence using this code according to this comments:Then send theough the port the encoded byte sequence pointed to by "dst"Quote:
Code:/*
* StuffData byte stuffs "length" bytes of
* data at the location pointed to by "ptr",
* writing the output to the location pointed
* to by "dst".
*/
Yes, but i don't understand well how i can do it.
You have to declare a destination buffer long enough to contain your encoded byte sequence, then call this StuffData function passing in your original byte array, its length and destination buffer.
Then send what destination buffer will get after this function returns to the serial port.
I have some problems...I'm a new programmer and all codes are not simple for me now. Are there some example code to understand how i can do it?
Thank you and I'm sorry.
Well, did you read some books about progamming with C++ for Windows?
Did you try some simple sample applications like "Hello Worlds"?
Some others a little more complicated?
Note, that you cannot from the level "zero" jump to a level for programming serial port communications...
So...
I'm reading and I'm trying many applications.
I'm improving and now i'm trying and I'd like to estabilish a connection between 2 devices also if it's not very simple for me.