private void i2cScanButton_Click(object sender, EventArgs e) { string ipstr = ipAddrTextBox.Text; string gpibAddr = "inst30"; string resp; VXI11Class remote_inst = new VXI11Class(gpibAddr, ipstr); // scan test byte[] i2cInst = new byte[128]; remote_inst.scanI2c(ref i2cInst); i2cRespTextBox.AppendText("i2c scan:\r\n"); for (int k = 3; k < 128; k++) { // if not zero, then i2c instrument is present if (i2cInst[k] != 0) { //Console.WriteLine("Hex: {0:X}", k); resp = String.Format("0x{0:X}", k); i2cRespTextBox.AppendText(resp + "\r\n"); } } i2cRespTextBox.AppendText("\r\n"); remote_inst.close(); }
private void uartWriteButton_Click(object sender, EventArgs e) { string inputStr = uartComboBox.Text; string[] strAry = null; int len = 0; string ipstr = ipAddrTextBox.Text; string gpibAddr = "inst29"; string resp; byte[] byteAry1 = null; if (inputStr == string.Empty) { return; } if (inputStr.Contains(@"/")) { // this is in hex strAry = inputStr.Split(new char[] { '/' }); } else { if (!newLineCheckBox1.Checked) { Regex regex = new Regex(@"\\n"); Match m = regex.Match(inputStr); if (m.Success) { byteAry1 = Encoding.ASCII.GetBytes(inputStr.ToCharArray(), 0, inputStr.Length - 1); byteAry1[inputStr.Length - 2] = 0x0a; // putting newline in ascii } else { byteAry1 = Encoding.ASCII.GetBytes(inputStr); } } else { // check box is check, add new line to the input string inputStr = inputStr + Environment.NewLine; byteAry1 = Encoding.ASCII.GetBytes(inputStr); } len = byteAry1.Length; //byte[] newline = Encoding.ASCII.GetBytes(Environment.NewLine); } VXI11Class remote_inst = new VXI11Class(gpibAddr, ipstr); remote_inst.uartWriteBytes(len, byteAry1); remote_inst.close(); uartRespTextBox.AppendText("uart write:"); uartRespTextBox.AppendText(inputStr); }
private void getUartConfig_Click(object sender, EventArgs e) { string ipstr = ipAddrTextBox.Text; string gpibAddr = "inst29"; string resp; int byteTimeout_us = Convert.ToInt32(byteTimeoutComboBox.Text); int msgTimeout_ms = Convert.ToInt32(msgTimeoutComboBox.Text); int dataRate = Convert.ToInt32(uartDataRateComboBox.Text); byte uartStopbit = Convert.ToByte(uartStpBitComboBox.Text); byte uartNumbit = Convert.ToByte(uartNumBitComboBox.Text); byte uartParity = 0; VXI11Class remote_inst = new VXI11Class(gpibAddr, ipstr); remote_inst.uartGetConfig(ref dataRate, ref uartNumbit, ref uartParity, ref uartStopbit, ref msgTimeout_ms, ref byteTimeout_us); remote_inst.close(); uartNumBitComboBox.Text = Convert.ToString(uartNumbit); uartDataRateComboBox.Text = Convert.ToString(dataRate); uartStpBitComboBox.Text = Convert.ToString(uartStopbit); msgTimeoutComboBox.Text = Convert.ToString(msgTimeout_ms); byteTimeoutComboBox.Text = Convert.ToString(byteTimeout_us); switch (uartParity) { case 0x00: uartParityComboBox.Text = "None"; break; case 0x01: uartParityComboBox.Text = "Odd"; break; case 0x02: uartParityComboBox.Text = "Even"; break; } }
private void readButton_Click(object sender, EventArgs e) { string ipstr = ipAddrTextBox.Text; string gpibAddr = "inst" + gpibAddrTextBox.Text; string cmd = commandComboBox.Text; int timeout_ms = 0; VXI11Class remote_inst = new VXI11Class(gpibAddr, ipstr); //string resp = string.Empty; string readstring = string.Empty; byte[] resp = null; try { /*if (LockDeviceCheckBox.Checked) * { * // device lock is requested, min 1000 ms is chosen for demo * // * if (Convert.ToInt32(timeOutTextBox.Text) >= 1000) * { * resp = remote_inst.read(Convert.ToInt32(timeOutTextBox.Text)); * } * } * else * { * resp = remote_inst.read(); * }*/ resp = remote_inst.readBytes(); } catch (VisaException ex) { readstring = ex.ErrorCode.ToString(); } Console.WriteLine(resp); readstring = System.Text.Encoding.ASCII.GetString(resp); responseTextBox.Text += readstring + "\r\n\r\n"; remote_inst.close(); }
private void setUartConfigButton_Click(object sender, EventArgs e) { int byteTimeout_us = Convert.ToInt32(byteTimeoutComboBox.Text); int msgTimeout_ms = Convert.ToInt32(msgTimeoutComboBox.Text); int dataRate = Convert.ToInt32(uartDataRateComboBox.Text); byte uartStopbit = Convert.ToByte(uartStpBitComboBox.Text); byte uartNumbit = Convert.ToByte(uartNumBitComboBox.Text); byte uartParity = 0; switch (uartParityComboBox.Text) { case "None": uartParity = 0; break; case "Odd": uartParity = 1; break; case "Even": uartParity = 2; break; default: break; } string ipstr = ipAddrTextBox.Text; string gpibAddr = "inst29"; VXI11Class remote_inst = new VXI11Class(gpibAddr, ipstr); remote_inst.uartSetConfig(dataRate, uartNumbit, uartParity, uartStopbit, msgTimeout_ms, byteTimeout_us); remote_inst.close(); }
private void uartReadButton_Click(object sender, EventArgs e) { // Read is actually a special case of write, with inputstr length of zero string inputStr = string.Empty; string[] strAry = null; int len = 0; string ipstr = ipAddrTextBox.Text; string gpibAddr = "inst29"; byte[] resp = null; byte[] byteAry1 = null; string respStr = string.Empty; /*if (inputStr.Contains(@"/")) * { * // this is in hex * strAry = inputStr.Split(new char[] { '/' }); * * } * else * { * * if (!newLineCheckBox1.Checked) * { * Regex regex = new Regex(@"\\n"); * Match m = regex.Match(inputStr); * if (m.Success) * { * byteAry1 = Encoding.ASCII.GetBytes(inputStr.ToCharArray(), 0, inputStr.Length - 1); * byteAry1[inputStr.Length - 2] = 0x0a; // putting newline in ascii * } * else * { * byteAry1 = Encoding.ASCII.GetBytes(inputStr); * } * } * else * { * // check box is check, add new line to the input string * inputStr = inputStr + Environment.NewLine; * byteAry1 = Encoding.ASCII.GetBytes(inputStr); * } * * len = byteAry1.Length; // this has to be zero * //byte[] newline = Encoding.ASCII.GetBytes(Environment.NewLine); * }*/ VXI11Class remote_inst = new VXI11Class(gpibAddr, ipstr); remote_inst.TimeOut = 15000;//Convert.ToInt32(byteTimeoutComboBox.Text) / 1000 + 500; Console.WriteLine(remote_inst.TimeOut); remote_inst.BufferSize = 40000; //remote_inst.uartReadBytes(ref resp); remote_inst.uartQueryBytes(0, null, ref resp); string readstring = System.Text.Encoding.ASCII.GetString(resp); Console.WriteLine(resp.Length); //Console.WriteLine(readstring); //uartTextBox.Text = readstring; double[] real64 = null; if (binDecode.Checked) { remote_inst.binaryToDouble64(resp, ref real64, swapBinOrder.Checked); if (real64 != null) { readstring = ""; for (int kk = 0; kk < real64.Length; kk++) { if (kk > 0) { readstring += "," + Convert.ToString(real64[kk]); } else { readstring = Convert.ToString(real64[kk]); } } } } uartRespTextBox.AppendText(@"uart read:"); uartRespTextBox.AppendText(readstring + "\r\n"); remote_inst.close(); }
private void uartQueryButton_Click(object sender, EventArgs e) { string inputStr = uartComboBox.Text; string[] strAry = null; int len = 0; string ipstr = ipAddrTextBox.Text; string gpibAddr = "inst29"; byte[] resp = null; byte[] byteAry1 = null; string respStr = string.Empty; if (inputStr == string.Empty) { return; } if (inputStr.Contains(@"/")) { // this is in hex strAry = inputStr.Split(new char[] { '/' }); } else { if (!newLineCheckBox1.Checked) { Regex regex = new Regex(@"\\n"); Match m = regex.Match(inputStr); if (m.Success) { byteAry1 = Encoding.ASCII.GetBytes(inputStr.ToCharArray(), 0, inputStr.Length - 1); byteAry1[inputStr.Length - 2] = 0x0a; // putting newline in ascii } else { byteAry1 = Encoding.ASCII.GetBytes(inputStr); } } else { // check box is check, add new line to the input string inputStr = inputStr + Environment.NewLine; byteAry1 = Encoding.ASCII.GetBytes(inputStr); } len = byteAry1.Length; //byte[] newline = Encoding.ASCII.GetBytes(Environment.NewLine); } VXI11Class remote_inst = new VXI11Class(gpibAddr, ipstr); remote_inst.TimeOut = 15000;//Convert.ToInt32(byteTimeoutComboBox.Text) / 1000 + 500; Console.WriteLine(remote_inst.TimeOut); remote_inst.BufferSize = 40000; remote_inst.uartQueryBytes(len, byteAry1, ref resp); string readstring = System.Text.Encoding.ASCII.GetString(resp); Console.WriteLine(resp.Length); //Console.WriteLine(readstring); //uartTextBox.Text = readstring; double[] real64 = null; if (binDecode.Checked) { remote_inst.binaryToDouble64(resp, ref real64, swapBinOrder.Checked); if (real64 != null) { readstring = ""; for (int kk = 0; kk < real64.Length; kk++) { if (kk > 0) { readstring += "," + Convert.ToString(real64[kk]); } else { readstring = Convert.ToString(real64[kk]); } } } } uartRespTextBox.AppendText(inputStr); uartRespTextBox.AppendText(readstring); remote_inst.close(); uartComboBox.Items.Add(inputStr); }
private void queryButton_Click(object sender, EventArgs e) { string ipstr = ipAddrTextBox.Text; string gpibAddr = "inst" + gpibAddrTextBox.Text; string cmd = commandComboBox.Text; Console.WriteLine(cmd); VXI11Class remote_inst = null;// new VXI11Class(gpibAddr, ipstr); //string resp = string.Empty; byte[] resp = null; try { remote_inst = new VXI11Class(gpibAddr, ipstr); /* if (LockDeviceCheckBox.Checked) * { * // device lock is requested, min 1000 ms is chosen for demo * // * if (Convert.ToInt32(timeOutTextBox.Text) >= 1000) * { * //resp = remote_inst.query(cmd, Convert.ToInt32(timeOutTextBox.Text)); * resp = remote_inst.queryByte(cmd, Convert.ToInt32(timeOutTextBox.Text)); * } * } * else * { * //resp = remote_inst.query(cmd); * resp = remote_inst.queryByte(cmd); * }*/ resp = remote_inst.queryByte(cmd); } catch (Exception ex) { //resp = ex.ErrorCode.ToString(); //resp = ex.Message; throw ex; } string readstring = System.Text.Encoding.ASCII.GetString(resp); //Console.WriteLine(readstring); byte[] bytesAry = resp;// System.Text.Encoding.ASCII.GetBytes(resp);//BitConverter.GetBytes(resp.ToCharArray()); double[] real64 = null; if (binDecode.Checked) { remote_inst.binaryToDouble64(bytesAry, ref real64, swapBinOrder.Checked); if (real64 != null) { readstring = ""; for (int kk = 0; kk < real64.Length; kk++) { if (kk > 0) { readstring += "," + Convert.ToString(real64[kk]); } else { readstring = Convert.ToString(real64[kk]); } } } } responseTextBox.Text += readstring + "\r\n\r\n"; remote_inst.close(); commandComboBox.Items.Add(cmd); }
private void i2cQueryButton_Click(object sender, EventArgs e) { byte i2cAddr = 0; byte regAddr = 0; byte numOfBytes = 0; string inputStr = i2cAddrTextBox.Text; string[] strAry = null; string ipstr = ipAddrTextBox.Text; string gpibAddr = "inst30"; string resp; VXI11Class remote_inst = new VXI11Class(gpibAddr, ipstr); if (inputStr == string.Empty) { return; } if (inputStr.Contains(@"/")) { strAry = inputStr.Split(new char[] { '/' }); i2cAddr = Convert.ToByte(strAry[strAry.Length - 1], 16); } else { i2cAddr = Convert.ToByte(inputStr); } Console.WriteLine("i2c addr: " + i2cAddr.ToString()); // inputStr = i2cRegisterTextBox.Text; if (inputStr == string.Empty) { return; } if (inputStr.Contains(@"/")) { strAry = inputStr.Split(new char[] { '/' }); regAddr = Convert.ToByte(strAry[strAry.Length - 1], 16); } else { regAddr = Convert.ToByte(inputStr); } Console.WriteLine("i2c register: " + regAddr.ToString()); inputStr = i2cNumOfBytesTextBox.Text; if (inputStr == string.Empty) { return; } if (inputStr.Contains(@"/")) { strAry = inputStr.Split(new char[] { '/' }); numOfBytes = Convert.ToByte(strAry[strAry.Length - 1], 16); } else { numOfBytes = Convert.ToByte(inputStr); } Console.WriteLine("number of bytes I2C read: " + numOfBytes.ToString()); byte[] data = new byte[numOfBytes]; i2cRespTextBox.AppendText("i2c read->addr: " + i2cAddr.ToString() + ", reg: " + regAddr.ToString() + "\r\n"); if (numOfBytes > 255) { i2cRespTextBox.AppendText(numOfBytes.ToString() + " bytes is greater than max 255 allowed" + "\r\n"); remote_inst.close(); return; } try { remote_inst.readI2c(i2cAddr, regAddr, Convert.ToByte(numOfBytes), ref data); } catch (Exception ex) { resp = ex.Message; i2cRespTextBox.AppendText(resp + "\r\n"); remote_inst.close(); return; } for (int j = 0; j < numOfBytes; j++) { resp = j.ToString() + ": " + String.Format("0x{0:X}", data[j]); i2cRespTextBox.AppendText(resp + "\r\n"); } i2cRespTextBox.AppendText("\r\n"); remote_inst.close(); i2cComboBox.Items.Add(inputStr); }
private void i2cWriteButton_Click(object sender, EventArgs e) { byte i2cAddr = 0; byte regAddr = 0; byte numOfBytes = 0; string inputStr = i2cAddrTextBox.Text; string[] strAry = null; string ipstr = ipAddrTextBox.Text; string gpibAddr = "inst30"; string resp; VXI11Class remote_inst = new VXI11Class(gpibAddr, ipstr); if (inputStr == string.Empty) { return; } if (inputStr.Contains(@"/")) { strAry = inputStr.Split(new char[] { '/' }); i2cAddr = Convert.ToByte(strAry[strAry.Length - 1], 16); } else { i2cAddr = Convert.ToByte(inputStr); } Console.WriteLine("i2c addr: " + i2cAddr.ToString()); // inputStr = i2cRegisterTextBox.Text; if (inputStr == string.Empty) { return; } if (inputStr.Contains(@"/")) { strAry = inputStr.Split(new char[] { '/' }); regAddr = Convert.ToByte(strAry[strAry.Length - 1], 16); } else { regAddr = Convert.ToByte(inputStr); } Console.WriteLine("i2c register: " + regAddr.ToString()); inputStr = i2cNumOfBytesTextBox.Text; if (inputStr == string.Empty) { return; } if (inputStr.Contains(@"/")) { strAry = inputStr.Split(new char[] { '/' }); numOfBytes = Convert.ToByte(strAry[strAry.Length - 1], 16); } else { numOfBytes = Convert.ToByte(inputStr); } Console.WriteLine("number of bytes I2C write: " + numOfBytes.ToString()); inputStr = i2cComboBox.Text; if (inputStr == string.Empty) { return; } byte[] data = new byte[numOfBytes]; if (inputStr.Contains(@"/")) { strAry = inputStr.Split(new char[] { '/' }); // first element is ignored due to / char data = new byte[strAry.Length - 1]; for (int j = 1; j < strAry.Length; j++) { data[j - 1] = Convert.ToByte(strAry[j], 16);// or byte.Parse(strAry[j], System.Globalization.NumberStyles.HexNumber); } } i2cRespTextBox.AppendText("i2c write-> add: " + i2cAddr.ToString() + ", reg: " + regAddr.ToString() + "\r\n"); // check if there is any differences between number of bytes versus i2c data to write (i2cComboBox) if (numOfBytes != strAry.Length) { numOfBytes = (byte)(strAry.Length - 1); } if (numOfBytes > 255) { i2cRespTextBox.AppendText(numOfBytes.ToString() + " bytes is greater than max 255 allowed" + "\r\n"); remote_inst.close(); return; } try { remote_inst.writeI2c(i2cAddr, regAddr, Convert.ToByte(numOfBytes), data); } catch (Exception ex) { resp = ex.Message; i2cRespTextBox.AppendText(resp + "\r\n"); } i2cRespTextBox.AppendText(inputStr + "\r\n"); remote_inst.close(); }