| |

VerySource

 Forgot password?
 Register
Search
View: 904|Reply: 3

MSComm control serial data processing problem

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-15 11:30:02
| Show all posts |Read mode
The data sent by the external device to the serial port is hexadecimal, and I read it in binary:
m_ComPort.SetInputMode (1);
What should I do with the data after reading it to convert it to a decimal number?
VARIANT variant_inp;
COleSafeArray safearray_inp;
LONG len, k;
BYTE rxdata [2048]; // Set BYTE array
CString strtemp;
if (m_ctrlComm.GetCommEvent () == 2)
{
variant_inp = m_ctrlComm.GetInput (); // Read buffer
safearray_inp = variant_inp; // VARIANT type variables are converted to ColeSafeArray type variables
len = safearray_inp.GetOneDimSize (); // Get effective data length
for (k = 0; k <len; k ++)
safearray_inp.GetElement (&k, rxdata + k); // Convert to BYTE type array


When i write like this
safearray_inp = variant_inp; // VARIANT type variables are converted to ColeSafeArray type variables
When the program is running, I get an exception in this sentence.I read a lot of information and wrote it like this. I don't know why. Please help me!
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-15 00:00:01
| Show all posts
This...the computer doesn't matter what decimal or hexadecimal you are... these prohibitions are all prescribed by people for good communication!
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-15 12:15:01
| Show all posts
However, if it is a simple serial port application, you can use the control. The more complicated one is the API, which is flexible and convenient, and the MSCOMM control has a bug under high-speed communication.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-7-28 07:45:02
| Show all posts
No one answered?
What should I do if the data I read is incomplete?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list