//iCount=dataread[5]; string connstr =
System.Configuration.ConfigurationManager.AppSettings[\ring\
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
//if (dataread[0] == 0xAA) //{
// //
MessageBox.Show(productline.ToString(), \MessageBoxIcon.Error);
// numbers = 0; // numbers =
Convert.ToInt32(dataread[4]) * 256 ^ 1 + Convert.ToInt32(dataread[5]); // numbers =
Convert.ToInt32(dataread[4]) * Convert.ToInt32(System.Math.Pow(256, 1)) + Convert.ToInt32(dataread[5]);
// SqlCommand cmd = new SqlCommand(\
// cmd.CommandType = CommandType.StoredProcedure;
// cmd.Parameters.Add(\tity\
// cmd.Parameters[\\
// cmd.Parameters.Add(\s\
// cmd.Parameters[\Value = dataread[3];
// cmd.ExecuteNonQuery(); //}
byte[] DataRead; int bytData ; int bytnum;
//bytnum = serialPort1.ReadByte; ;
// TODO: NotImplemented statement: ICSharpCode.SharpRefactory.Parser.AST.VB.OnErrorStatement if (serialPort1.ReceivedBytesThreshold == serialPort1.ReceivedBytesThreshold) {
bytnum = serialPort1.BytesToRead;
DataRead = new byte[bytnum]; // TODO: NotImplemented statement: ICSharpCode.SharpRefactory.Parser.AST.VB.ReDimStatement for (int k = 0; k <= (bytnum - 1); k++)
{
bytData= serialPort1.ReadByte();
DataRead[k] =(byte) bytData;
bfinish = RFJ(DataRead[k]);
if (bfinish) {
//System.Convert.ToInt32(RCmd)为端口号
iCount = 0; for (int j = 0; j <= 1; j++)
{
iCount += System.Convert.ToInt32(RParam[j]) * Convert.ToInt32(Math.Pow(256, j));
} cmd = new SqlCommand(\ ype = CommandType.StoredProcedure;
rs.Add(\
rs[\
rs.Add(\
SqlCommand cmd.CommandT cmd.Paramete cmd.Paramete cmd.Paramete
cmd.Parameters[\
cmd.ExecuteNonQuery();
} } }
}
catch (IOException ex) {
throw (ex); }
}
private void timer1_Tick(object sender, EventArgs e) {
//this.Opacity -= -0.1; //if (this.Opacity==0) //{
// timer1.Enabled = false; // this.Close(); //} }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
Win32.AnimateWindow(this.Handle, 2500, Win32.AW_SLIDE | Win32.AW_HIDE | Win32.AW_BLEND); // e.Cancel = true; //timer1.Enabled = true; }
private void Btn_OK_Click(object sender, EventArgs e) {
popupNotifier1.Popup(); }
private bool RFJ(byte Data)
{
bool result=false; if (bRStart == 0) {
if (Data == 0xAA) {
bRStart = 1; } }
else if (bRStart == 1) {
if (Data == 0x55) {
bRStart = 2; }
else if (Data == 0xAA) {
bRStart = 1; } else {
bRStart = 0; } }
else if (bRLenth == false) {
if (Data < 20) {
bRLenth = true; rlenth = Data; Rchk = Data;
LParam = (int)(rlenth) - 3; RParam = new byte[2]; } else {
bRStart = 0; } }
else if (brcmd == false) {
brcmd = true; RCmd = Data;
Rchk = (byte)(Rchk ^ Data); }
else if (bRParam == false) {
if (LParam >= 0) {
RParam[LParam] = Data;
Rchk = (byte)(Rchk ^ Data); LParam = LParam - 1; }
if (LParam < 0) {
bRParam = true; } }
else if (bRchk == false) {
if (Rchk == Data) {
result = true; } else {
bRStart = 0; bRLenth = false; brcmd = false; bRParam = false; } }
return result; }
} }
使用SerialPort类设计串口通讯程序 2007-12-10 14:11