I need to send a packet of type byte: 0x00, 0x01, 0x02, 0x11, 0x00, 0x00 to a device via the serial port and then I receive and store data coming from device like this: 0x01, 0x01, 0x01 , 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x01, 0x00.
Someone could send me lines of code through which:
1) I create the array
2) the sending the array to serial port
3) I'll see what I'm sending
4) I get the data
I'm using Visual Studio 2010 and C + + or VC++ language.
I hope someone can help me
greetings
f
I'm trying to test the code: http://www.planet-source-code.com/vb...d=144&lngWId=3
I have to send the bytes via bluetooth, so I'm looking for the part that deals with the trasmission and reception of bytes in this code. I'd like to add this part in my code . Now i'm able to open serial port and to find the bluetooth device, but maybe i'm not able to send and to receive the bytes correctly. I'll show you my code (i modified a code that i have found in internet):
// add sender name
String^ name = this->serialPort1->PortName;
// grab text and store in send buffer
String^ message = this->textBox2->Text;
//write to serial
if(this->serialPort1->IsOpen){
array<Byte>^TxBfr={0x00,0x02,0x06,0x13,0x01,0x01,0x00};
this->serialPort1->Write(TxBfr,0,7);
The code that you "have found in internet" has nothing to do with Visual C++ one, nor is it a valid native C++.
It looks like a managed C++ code that is discussed in another (Managed C++/CLI) forum.
Ah ok thank you.
I'm not an expert. I prefer programming in native C + + or Visual C + +, but for now I only found that code for communication Bluethooth. Maybe I could use the code in http://www.planet-source-code.com/vb...d=144&lngWId=3
AFAIK it doesn't matter whether you use Bluethooth or infraRed or USB or some other communications. It is up to Bluethooth drivers to emulate correct serial port communications. So you can use the same code to communicate with Bluethooth port as it would be a "classic" serial port. (otherwise, it had to supply some SDK or APIs for communications with it!)
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\devobj.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': scaricato 'C:\Windows\SysWOW64\serialui.dll'
'SerialPort.exe': scaricato 'C:\Windows\SysWOW64\setupapi.dll'
'SerialPort.exe': scaricato 'C:\Windows\SysWOW64\devobj.dll'
'SerialPort.exe': scaricato 'C:\Windows\SysWOW64\cfgmgr32.dll'
Failed in call to TransmitCommChar
Warning: throwing CSerialException for error 1
Eccezione first-chance a 0x7686c41f in SerialPort.exe: Eccezione di Microsoft C++: CSerialException nella posizione di memoria 0x002efc00..
Handle Exception, Message:Funzione non corretta.
Sorry, I cannot understand the output you have provided. Could you translate it?
Besides, your could try the more recent version of CSerialPort class from http://www.naughter.com/serialport.html
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\ntdll.dll', Impossibile trovare o aprire il file PDB (trad:Impossibile trovare o aprire il file PDB=Can not find or open the PDB file)
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\kernel32.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\KernelBase.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\mfc100d.dll', Simboli caricati.
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\msvcr100d.dll', Simboli caricati.
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\user32.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\gdi32.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\lpk.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\usp10.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\msvcrt.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\advapi32.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\sechost.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\rpcrt4.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\sspicli.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\cryptbase.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\shlwapi.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\comctl32.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\msimg32.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\oleaut32.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\ole32.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\imm32.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\msctf.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Program Files (x86)\Kaspersky Lab\Kaspersky Anti-Virus 6.0 for Windows Workstations MP4\adialhk.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Program Files (x86)\Kaspersky Lab\Kaspersky Anti-Virus 6.0 for Windows Workstations MP4\kloehk.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\uxtheme.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\dwmapi.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\mfc100ita.dll', Il file binario non è stato compilato con le informazioni di debug.
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\cfgmgr32.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': scaricato 'C:\Windows\SysWOW64\cfgmgr32.dll'
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\serialui.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\setupapi.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\cfgmgr32.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': caricato 'C:\Windows\SysWOW64\devobj.dll', Impossibile trovare o aprire il file PDB
'SerialPort.exe': scaricato 'C:\Windows\SysWOW64\serialui.dll'
'SerialPort.exe': scaricato 'C:\Windows\SysWOW64\setupapi.dll'
'SerialPort.exe': scaricato 'C:\Windows\SysWOW64\devobj.dll'
'SerialPort.exe': scaricato 'C:\Windows\SysWOW64\cfgmgr32.dll'
'SerialPort.exe': scaricato 'C:\Program Files (x86)\Kaspersky Lab\Kaspersky Anti-Virus 6.0 for Windows Workstations MP4\adialhk.dll'
Il thread 'Thread Win32' (0x1138) è terminato con il codice 0 (0x0).
CSerialPort::Open, Failed to open the comms port, Error:121
Warning: throwing CSerialException for error 121
The "error" 'Impossibile trovare o aprire il file PDB' is just an information that the loaded dll doesn't have any debugging info.
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
Even though you may actually manage to get your C++/CLI program working with the native CSerialPort class, I'd strongly recommend against using it. The .NET framework provides the handy SerialPort class which you should use instead.
Unnecessarily combining managed and native code can considerably complicate things, which is particularly true when multithreading is involved, and that's the case in properly designed serial communication code. The complication may be so drammatic that you need to take more effort to have the managed and native parts of your program cooperate properly (the so-called interop) than to write the code that your program actually needs to do what it is supposed to do.
@Eri523: Thank you very much for your reply! I'm trying to use only native C++ now.
@VictorN: I read that error when i compile only the class in http://www.naughter.com/serialport.html. Now I'm trying to find a sample code in C++ native, able to send and to receive arrays of bytes(using the class that you showed me).
Bookmarks