M
Mikey.VB
Guest
I am trying to figure out the way to communicate with an equipment that is ASTM protocol based.
the communication consist of two phases.
Phase 1 : reading data FROM the equipment > already done !
Phase 2 : sending data TO the equipment > Stuck with
to read the data I use this code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ASTM;
using System.IO.Ports;
using System.Threading;
using System.Data.OracleClient;
namespace TestMessage
{
class Program
{
const int wait = 3000;
const int cihazId = 2;
static string soh = char.ConvertFromUtf32(1);
static string stx = char.ConvertFromUtf32(2);
static string etx = char.ConvertFromUtf32(3);
static string eot = char.ConvertFromUtf32(4);
static string enq = char.ConvertFromUtf32(5);
static string ack = char.ConvertFromUtf32(6);
static string nack = char.ConvertFromUtf32(21);
static string etb = char.ConvertFromUtf32(23);
static string lf = char.ConvertFromUtf32(10);
static string cr = char.ConvertFromUtf32(13);
static SerialPort sp;
static EventWaitHandle wh;
static bool orderFlag = false;
static void Main(string[] args)
{
Console.WindowWidth = 120;
Console.ForegroundColor = ConsoleColor.Green;
Console.Title = "Host";
//Console.WriteLine(Console.WindowWidth.ToString());
sp = new SerialPort("COM1");
sp.DataReceived+=new SerialDataReceivedEventHandler(sp_DataReceived);
sp.Open();
Console.WriteLine("[port opened]");
Console.ReadKey();
}
static void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string str = sp.ReadExisting();
Eval(str);
Console.WriteLine("[received]" + Display(str));
}
private static void Eval(string str)
{
string received;
Thread thread;
received = null;
received = str;
Console.WriteLine("[received]" + Display(received));
if (received == ack)
{
wh.Set();
}
else if (received == enq)
{
ACK();
}
else if (received == eot)
{
if (orderFlag)
{
thread = new Thread(new ThreadStart(SerialWrite));
thread.Start();
orderFlag = false;
//Console.WriteLine("[Host ~]$ Analyzer Queries {0}", _barcode);
//Console.WriteLine("[Host ~]$ Retrieving {0} tests from LIS", _barcode);
}
}
else
{
string recordType = received[2].ToString();
switch (recordType)
{
case "H":
ACK();
break;
case "Q":
string[] fields = received.Split('|');
string[] comps = fields[2].Split('^');
//string barcode = comps[1];
//_barcode = Convert.ToInt32(barcode);
orderFlag = true;
ACK();
break;
case "R":
string test = "";
string result = "";
string resultUnit = "";
test = received.Split('|').GetValue(2).ToString();
result = received.Split('|').GetValue(3).ToString();
resultUnit = received.Split('|').GetValue(4).ToString();
Update( test, result, resultUnit);
//Update(_barcode, test, result, resultUnit);
ACK();
break;
//case "O":
// _barcode = Convert.ToInt32(received.Split('|').GetValue(2).ToString());
// ACK();
//break;
case "L":
ACK();
break;
default:
ACK();
break;
}
}
}
I need to know how do you SEND data to the equipment according to this
HOST [ENQ]
Equipment[ACK]
HOST[STX]1H|\^&| | |ASTM-Host[CR][ETX]59[CR][LF]
Equipment [ACK]
HOST[STX]2P|1[CR][ETX]3F[CR][LF]
Equipment[ACK]
HOST[STX]3O|1|000083|135^0^1^^SAMPLE^NORMAL \^^^10^0\^^^150^0|R| | | | | |N| | | | | | | | | | | | | |Q[CR] [ETX]F9[CR][LF]
HOST[STX]4L|1[CR][ETX]3D[CR][LF]
Equipment[ACK]
HOST[EOT]
using the code above I am able to view data from the equipment in this way
Equimpent [ENQ]
HOST [ACK]
Equipment[STX]1H|\^&| | | | | | | | | |P| |[CR][ETX]05[CR][LF]
HOST [ACK]
Equipment [STX]2P|1| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |[CR][ETX]3B[CR][LF]
HOST [ACK]
Equipment [STX]3O|1|000083|135^0^1^^SAMPLE^ NORMAL|ALL|R |19980403090614| | | | |X| | | | | | | | | | | | | |O| | | | |[CR][ETX]79[CR][LF]
HOST [ACK]
Equipment [STX]4R|1|^^^10^0| 2.73|ulU/ml|0.270^4.20|N| |F| | |19980403090641|19980403092503|[CR][ETX] B7[CR]
HOST [ACK]
Equipment[STX]6L|1[CR][ETX]3F[CR][LF]
HOST [ACK]
Equipment [EOT]
---------------------------------------------------
basicailly I am just replying with [ACK] to every line so i can get the next one . but the question is , how do I write back ?
Thanks in advance.
Continue reading...
the communication consist of two phases.
Phase 1 : reading data FROM the equipment > already done !
Phase 2 : sending data TO the equipment > Stuck with
to read the data I use this code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ASTM;
using System.IO.Ports;
using System.Threading;
using System.Data.OracleClient;
namespace TestMessage
{
class Program
{
const int wait = 3000;
const int cihazId = 2;
static string soh = char.ConvertFromUtf32(1);
static string stx = char.ConvertFromUtf32(2);
static string etx = char.ConvertFromUtf32(3);
static string eot = char.ConvertFromUtf32(4);
static string enq = char.ConvertFromUtf32(5);
static string ack = char.ConvertFromUtf32(6);
static string nack = char.ConvertFromUtf32(21);
static string etb = char.ConvertFromUtf32(23);
static string lf = char.ConvertFromUtf32(10);
static string cr = char.ConvertFromUtf32(13);
static SerialPort sp;
static EventWaitHandle wh;
static bool orderFlag = false;
static void Main(string[] args)
{
Console.WindowWidth = 120;
Console.ForegroundColor = ConsoleColor.Green;
Console.Title = "Host";
//Console.WriteLine(Console.WindowWidth.ToString());
sp = new SerialPort("COM1");
sp.DataReceived+=new SerialDataReceivedEventHandler(sp_DataReceived);
sp.Open();
Console.WriteLine("[port opened]");
Console.ReadKey();
}
static void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string str = sp.ReadExisting();
Eval(str);
Console.WriteLine("[received]" + Display(str));
}
private static void Eval(string str)
{
string received;
Thread thread;
received = null;
received = str;
Console.WriteLine("[received]" + Display(received));
if (received == ack)
{
wh.Set();
}
else if (received == enq)
{
ACK();
}
else if (received == eot)
{
if (orderFlag)
{
thread = new Thread(new ThreadStart(SerialWrite));
thread.Start();
orderFlag = false;
//Console.WriteLine("[Host ~]$ Analyzer Queries {0}", _barcode);
//Console.WriteLine("[Host ~]$ Retrieving {0} tests from LIS", _barcode);
}
}
else
{
string recordType = received[2].ToString();
switch (recordType)
{
case "H":
ACK();
break;
case "Q":
string[] fields = received.Split('|');
string[] comps = fields[2].Split('^');
//string barcode = comps[1];
//_barcode = Convert.ToInt32(barcode);
orderFlag = true;
ACK();
break;
case "R":
string test = "";
string result = "";
string resultUnit = "";
test = received.Split('|').GetValue(2).ToString();
result = received.Split('|').GetValue(3).ToString();
resultUnit = received.Split('|').GetValue(4).ToString();
Update( test, result, resultUnit);
//Update(_barcode, test, result, resultUnit);
ACK();
break;
//case "O":
// _barcode = Convert.ToInt32(received.Split('|').GetValue(2).ToString());
// ACK();
//break;
case "L":
ACK();
break;
default:
ACK();
break;
}
}
}
I need to know how do you SEND data to the equipment according to this
HOST [ENQ]
Equipment[ACK]
HOST[STX]1H|\^&| | |ASTM-Host[CR][ETX]59[CR][LF]
Equipment [ACK]
HOST[STX]2P|1[CR][ETX]3F[CR][LF]
Equipment[ACK]
HOST[STX]3O|1|000083|135^0^1^^SAMPLE^NORMAL \^^^10^0\^^^150^0|R| | | | | |N| | | | | | | | | | | | | |Q[CR] [ETX]F9[CR][LF]
HOST[STX]4L|1[CR][ETX]3D[CR][LF]
Equipment[ACK]
HOST[EOT]
using the code above I am able to view data from the equipment in this way
Equimpent [ENQ]
HOST [ACK]
Equipment[STX]1H|\^&| | | | | | | | | |P| |[CR][ETX]05[CR][LF]
HOST [ACK]
Equipment [STX]2P|1| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |[CR][ETX]3B[CR][LF]
HOST [ACK]
Equipment [STX]3O|1|000083|135^0^1^^SAMPLE^ NORMAL|ALL|R |19980403090614| | | | |X| | | | | | | | | | | | | |O| | | | |[CR][ETX]79[CR][LF]
HOST [ACK]
Equipment [STX]4R|1|^^^10^0| 2.73|ulU/ml|0.270^4.20|N| |F| | |19980403090641|19980403092503|[CR][ETX] B7[CR]
HOST [ACK]
Equipment[STX]6L|1[CR][ETX]3F[CR][LF]
HOST [ACK]
Equipment [EOT]
---------------------------------------------------
basicailly I am just replying with [ACK] to every line so i can get the next one . but the question is , how do I write back ?
Thanks in advance.
Continue reading...