private void Form1_Load(object sender, System.EventArgs e) { int i, ret; string tmpstr; // System.Windows.Forms.MessageBox.Show( "testing") ; tmpstr = System.Reflection.Assembly.GetExecutingAssembly().Location; System.Windows.Forms.MessageBox.Show("Working Area=" + tmpstr); ret = API2.AB_API_Open(); if (ret < 0) { MessageBox.Show("AB_API_Open= err"); // + AB_ErrMsg(ret)) ; } else { timer1.Enabled = true; ret = AB_LoadConf(); if (ret > 0) { for (i = 0; i < ret; i++) { lstGwStatus.Items.Add("Gateway" + Convert.ToString(i + 1) + " not open"); ret = API2.AB_GW_Open(GwConf[i].gw_id); } } } }
private void RunState(object obj) { int clientId = 0; short iSubCmd = -1; short iCmdType = -1; short iCmdLen = 512; byte[] data = new byte[iCmdLen]; short ret = API2.AB_Tag_RcvMsg(ref clientId, ref iSubCmd, ref iCmdType, ref data[0], ref iCmdLen); if (ret > 0) { Console.WriteLine(ret); } }
private void menuItem4_Click(object sender, System.EventArgs e) { int ret, node; node = 22; ret = API2.AB_GW_Close(node); if (ret < 0) { MessageBox.Show("AB_GW_Close() err"); return; } else { MessageBox.Show("AB_GW_Close() ok, node=" + Convert.ToString(node)); } }
private void button1_Click(object sender, System.EventArgs e) { button1.Text = "hello"; int ret, node; node = 22; ret = API2.AB_GW_TagDiag(node, 0); if (ret < 0) { MessageBox.Show("AB_GW_TagDiag() err"); return; } else { MessageBox.Show("AB_GW_TagDiag() ok, node=" + Convert.ToString(node)); } }
public short AB_LoadConf() { string tmpstr; short ret; short i, j; int id, port; byte [] ip = new byte[20]; GwCnt = API2.AB_GW_Cnt(); if (GwCnt == 0) { return(0); } for (i = 0; i < GwCnt; i++) { ret = API2.AB_GW_Conf(i, out id, out ip[0], out port); if (ret >= 0) { GwConf[i].gw_id = (short)id; GwConf[i].port = (short)port; for (j = 0; j < 20; j++) { if (ip[j] == 0) { break; } } tmpstr = System.Text.Encoding.ASCII.GetString(ip, 0, j); GwConf[i].ip = tmpstr; } else { GwConf[i].gw_id = 0; GwConf[i].port = 0; GwConf[i].ip = ""; } } return(GwCnt); }
private void timer1_Tick(object sender, System.EventArgs e) { int i, cnt, ret; btnRecv_Click(sender, e); loopcnt++; if (loopcnt < 50) { return; } loopcnt = 0; cnt = API2.AB_GW_Cnt(); for (i = 0; i < cnt; i++) { ret = API2.AB_GW_Status(GwConf[i].gw_id); lstGwStatus.Items[i] = "Gateway index:" + Convert.ToString(i + 1) + " " + AB_ErrMsg(ret); } }
private void menuItem3_Click(object sender, System.EventArgs e) { int ret, node; string tmpstr; node = 22; ret = API2.AB_GW_Open(node); if (ret < 0) { MessageBox.Show("AB_GW_Open() err"); return; } else { tmpstr = "AB_GW_Open() ok, node=" + Convert.ToString(node); MessageBox.Show(tmpstr); MsgBox2(tmpstr); } }
/// <summary> /// 清除任何使用中的資源。 /// </summary> protected override void Dispose(bool disposing) { int ret; System.Windows.Forms.MessageBox.Show("Close Form"); timer1.Enabled = false; ret = API2.AB_GW_Close(0); ret = API2.AB_API_Close(); if (ret < 0) { MessageBox.Show("AB_API_Close= err"); // + AB_ErrMsg(ret)) ; } if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); }
private void btnRecv_Click(object sender, System.EventArgs e) { int ret, i, k; int tag_addr; short msg_type, subcmd, data_cnt; byte [] data = new byte [512]; byte ch; string tmpstr; // MessageBox.Show( "btnRecv_Click ") ; // + AB_ErrMsg(ret)) ; for (k = 1; k < 30; k++) { tag_addr = 0; subcmd = -1; msg_type = -1; data_cnt = 512; ret = API2.AB_Tag_RcvMsg(ref tag_addr, ref subcmd, ref msg_type, ref data[0], ref data_cnt); if (ret <= 0) //no data { break; } else { if (subcmd == 9) //---diagnosis status { tmpstr = ldump3(data, 0, data_cnt); tmpstr = String.Format("Diagnosis, Node={0}, port={1}, cnt={2}, data={3}", tag_addr >> 16, (tag_addr >> 8) & 0xFF, msg_type, tmpstr); MsgBox2(tmpstr); // ret = ChkStatus2(tag_addr, msg_type, data) ; } else //---DCS-19 data if (subcmd == 0x37) { if (msg_type == 0x30) { if (data[0] == 0) //Function key { tmpstr = String.Format("Press F{0}", data[1] - 0x3B + 1); } else { tmpstr = String.Format("Press {0}", data[1]); } } else if (msg_type == 0x31 || msg_type == 0x41) //keyboard input string { //---remove "\r\n" for (i = 1; i <= 2; i++) { if (data_cnt > 0) { ch = data[data_cnt - 1]; if (ch == 13 || ch == 10) { data_cnt -= 1; } else { break; } } } tmpstr = System.Text.Encoding.ASCII.GetString(data, 0, data_cnt); //---for English output byte [] tmpbytes = System.Text.Encoding.ASCII.GetBytes("Keyin:" + tmpstr + "\r\n"); API2.AB_DCS_DspStrE(tag_addr, ref tmpbytes[0], tmpbytes.Length); //---for Chinese output byte [] tmpbytes2 = System.Text.Encoding.Default.GetBytes("Output:" + tmpstr + "\r\n"); API2.AB_DCS_DspStrC(tag_addr, ref tmpbytes2[0], tmpbytes2.Length); } else //other message { tmpstr = ldump3(data, 0, data_cnt); tmpstr = String.Format("Unknown data, msg_type={0}, data={1}", msg_type, tmpstr); } tmpstr = String.Format("Get data, Node={0}, port={1}, addr={2}, data={3}", tag_addr >> 16, (tag_addr >> 8) & 0xFF, tag_addr & 0xFF, tmpstr); MsgBox2(tmpstr); } else //---unknown data { tmpstr = ldump3(data, 0, data_cnt); tmpstr = String.Format("Unknown data, Node={0}, port={1}, msg_type={2}, data={3}", tag_addr >> 16, (tag_addr >> 8) & 0xFF, msg_type, tmpstr); MsgBox2(tmpstr); } } // if ret>0 } //for k }