Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to recieve data from SPCI commands in C#

Status
Not open for further replies.

yefj

Advanced Member level 5
Advanced Member level 5
Joined
Sep 12, 2019
Messages
1,504
Helped
1
Reputation
2
Reaction score
5
Trophy points
38
Activity points
9,104
Hello,I have implemented the following code for controlling my spectrum analizer shown bellow.

I cant understand how to properly store a responce from my device. for example there is the simple *idn? command which returns the model. how do store properly the responce. i Have tried to use serialPort1.ReadTo but its description(shown bellow is not very informative. How do i store string responce from my spectrum analizer in C# Thanks.

1659973016441.png

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        bool meter_state = false;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            serialPort1.Open();
            serialPort1.Write("meas:freq:st 500 mhz\n");
            serialPort1.ReadTo
            serialPort1.Close();

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
 

From the hint description, it seems to be just that: The function starts the reading mode of the Serial device, and once found a string identical to the argument, it returns the substring of everything that precedes it, including the searched string itself. You will probably have to specify the timeout beforehand, and the treatment in case it occurs.
 

You have not declared a string variable for storage of the output of the function, neither have you given it a value to work with.
 

Hello,I am using putty and i think itends each recieved responce with "\n"(i cant see in putty the option of viewing the exact charcter response)
so i think i should use
Code:
serialPort1.Write("*idn?\n");
string data = serialPort1.ReadTo("\n")
but there is a logical error because on one line we send the data while on the other we recives the responce
It should be one line as shown bellow but its not working because Write function returns VOID.
Code:
string data=serialPort1.Write("*idn?\n")

1660033284638.png
 
Last edited by a moderator:

but there is a logical error because on one line we send the data while on the other we recives the responce
The logical error is only in your head. The serial interface receives all data to a buffer. ReadTo() or Read() simply retrieves data from the buffer.
 

Hello FVM,So if i send several commands which will be stored in a buffer.
by what order they will be retrieved if i put 3 read commands one after the other?
is it FIFO?
Thanks.
 

So if i send several commands which will be stored in a buffer.
by what order they will be retrieved
The most suited approach is to manage sending and receiving commands at distinct threads/tasks, with the appropriate timming/protocol control, otherwise your code would get stuck while waiting to receive the expected string/character.
 

Hello Andre,could you please show an example,so i could understand in practice what you mean?
Thanks.
 

In the two minutes elapsed between my answer and your reply, did you even made a search for the keywords above mentioned ?
I would expect that from your side; don't quite expect general tips followed by examples; there are lot of concepts behind.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top