Click here to Skip to main content
16,016,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
int[]temp_buf=new int[200];
temp_buf[] = serialPort1.ReadExisting();

What I have tried:

cannot implicitly convert type string[] to int[]
Posted
Updated 11-Jun-19 21:24pm

Why are you trying to store a string (which is at best a character array) in an array of integers?
What you need to do depends on exactly what the device at the other end of the serial port is sending you: and probably, it isn't "directly" numeric at all - it's either a string containing integer values with separators, or it's a sequence of byte values which shouldn't go anywhere near a string at all (because char values are Unicode 16 bit values, and the translation at occurs may corrupt your byte based data).

So start by looking at exactly what the device is sending - possibly using the SerialPort.Read Method (System.IO.Ports) | Microsoft Docs[^] instead of ReadExisting so you get the "raw" data - and work out exactly what is supposed to arrive.
And bear in mind that serial port data is very slow in comparison to your processor, so it is very unlikely that you will get the "whole message" in a single call to Read or ReadExisting - so converting data directly as it arrives can be a very poor way to do things.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900