Click here to Skip to main content
14,209,923 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

   

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



Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190617.3 | Last Updated 12 Jun 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100