.NET 4.x Обмен данными с устройством через com-порт - C#
Формулировка задачи:
Здравствуйте.
Я работаю с Акип'ом и мне нужно считывать с него измерения.
Проблема в том, что я не могу получить от него банальное имя, или статус.
Реализовал управление, то есть отправку команд, а прием не выходит.
Делал чтение таким способом:
И само собой событие:
Помогите пожалуйста.
Вот пример команды на проверку статуса кнопки Load : LOAD ;
В документации: [STATe:] LOAD ?{;⏐NL}
private void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
byte[] b = new byte[128];
target_port.Read(b, 0, b.Length);
string s = Encoding.ASCII.GetString(b);
richTextBox1.AppendText(s);
}this.target_port.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort_DataReceived);
Решение задачи: «.NET 4.x Обмен данными с устройством через com-порт»
textual
Листинг программы
/* Link this program with appropriate *cib*.obj. */
/* This application program is written in TURBO C 2.0 for the IBM PC-AT compatible. The National Instruments Cooperation (NIC) Model PC-2A board provides the interface between the PC-AT and a PRODIGIT MPAL ELECTRONIC LOAD. The appropriate *cib*.obj file is required in each program to properly link the NIC board to C LANGUAGE. and include the <decl.h.> HEADER FILE to C LANGUAGE. */
#include <stdio.h>
#include <dos.h>
#include <math.h>
#include "decl.h" /* NI GPIB CARD HEADER FILE */
main()
{ char ouster[20],rdbuf[15],spec[10];
int i,ch,load;
/* Assign unique identifier to the device "dev5" and store in variable load. check for error. ibfind error = negative value returned. */
if((load = ibfind("dev5")) < 0) /* Device variable name is load */
{ /* GPIB address is 5 */
printf("\r*** INTERFACE ERROR ! ***\a\n");
printf("\r\nError routine to notify that ibfind failed.\n");
printf("\r\nCheck software configuration.\n");
exit(1);
}
/* Clear the device */
if((ibclr(load)) & ERR);
{
printf("INTERFACE ERROR ! \a");
exit(1);
}
clrscr();
/* Clear load error register */
for(i=1,ch=0;i<=4;i++,ch++)
{
outstr=chan[ch];
ibwrt(load,outstr,6);
ibwrt(load,"CLER",4);
}
ibwrt( load,"NAME?",5); /* Get the 3310 series module load specification */
strset(rdbuf,'\0'); /* Clear rdbuf string buffer */
strset(spec,'\0'); /* Clear spec string buffer */
ibrd(load,spec,20);
if (spec[3] == '9')
printf("\n 3300F series specification error !");
/* Set the channel 1, preset off, current sink 1.0 amps and load on commands to the load. */
ibwrt( load,"chan 1;pres off;curr:low 0.0;curr high 1.0;load on ",51);
ibwrt( load,"meas:curr ?",11);
/* Get the load actially sink current from the load */
ibrd( load,rdbuf,20);
/* go to local. */
ibloc(load);
}