|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
Introduction
Serial port (RS-232) is still used in industrial applications but it has recently disappeared from the most of the notebooks.
In this project, I use a real device to communicate by using Hioki 3153 Hipot tester via serial port.Indication of the fail The Namespace
I use two different namespaces. One of them is hipotinterface which includes main program and serial port codes. The Main Code
Here is the code for serial port and main window. When the main form is loaded with FrmMain_Load event, all the parallel port
In the CommWith3153At9600 function, Hipot device communicates with our PC. You can read the 3153 To PC Interface section
The RunTest() function handles Red/Green label transformation, closing serial and parallel ports according to result using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.IO; using System.IO.Ports; using System.Threading; namespace hipotinterface { public partial class FrmMain : Form { //RS232 variables //Create a new SerialPort object with Hioki 3153 HiTester settings; public static SerialPort _serialPort = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One); public static string strTestResult = null; static bool _ESR0CommandSent = false; const string CRLF = "\r\n"; //Delimiter for 3153 private void FrmMain_Load(object sender, EventArgs e) { //change all parallel port data lines to low state. ParallelPort.HipotParPort.HipotParPort1(false); try { //Open Port _serialPort.Open(); _serialPort.ReadTimeout = 5000; //Send any Character To Pass 3153 to Remote Mode. _serialPort.WriteLine(CRLF); //Set Withstand Test-voltage type to :AC 50 Hz _serialPort.WriteLine("conf:with:kind AC50"); _serialPort.WriteLine(CRLF); //Set Withstand Test Voltage to 3.00kV _serialPort.WriteLine("conf:with:volt 3.00"); _serialPort.WriteLine(CRLF); //Set Withstand Cutoff current upper limit to 5.5 mA _serialPort.WriteLine("with:clow ON"); _serialPort.WriteLine(CRLF); _serialPort.WriteLine("conf:with:cupp 5.5"); _serialPort.WriteLine(CRLF); //Set Withstand Cutoff current lower limit to 0.7 mA _serialPort.WriteLine("conf:with:clow 0.7"); _serialPort.WriteLine(CRLF); //Set Withstand Ramp Timer(Test Time) to :3.0 s. _serialPort.WriteLine("with:tim ON"); _serialPort.WriteLine(CRLF); _serialPort.WriteLine("conf:with:tim 3.0"); _serialPort.WriteLine(CRLF); //Set Withstand Ramp-up Timer to OFF _serialPort.WriteLine("with:utim OFF"); _serialPort.WriteLine(CRLF); //Set Withstand Ramp-down Timer to OFF _serialPort.WriteLine("with:dtim OFF"); _serialPort.WriteLine(CRLF); //// //Set Insulation Test-voltage type to :DC _serialPort.WriteLine("conf:ins:kind AC50"); _serialPort.WriteLine(CRLF); //Set Insulation Test Voltage to 500V _serialPort.WriteLine("conf:ins:volt 500"); _serialPort.WriteLine(CRLF); //Set Insulation Resistance upper limit to :OFF. _serialPort.WriteLine("ins:rupp OFF"); _serialPort.WriteLine(CRLF); //Set Insulation Resistance lower limit to : 4.0 Mohm _serialPort.WriteLine("conf:ins:rlow 4.0"); _serialPort.WriteLine(CRLF); //Set Insulation Test Time to :1.0 s. _serialPort.WriteLine("ins:tim ON"); _serialPort.WriteLine(CRLF); _serialPort.WriteLine("conf:ins:tim 1.0"); _serialPort.WriteLine(CRLF); //Set Insulation delay time to OFF. _serialPort.WriteLine("ins:del OFF"); _serialPort.WriteLine(CRLF); //// //Set Test Mode: Withstand voltage mode -> insulation resistance mode _serialPort.WriteLine(":mode AWI"); _serialPort.WriteLine(CRLF); _serialPort.Close(); } catch (Exception) { MessageBox.Show("Initialization Error."); Application.Restart(); } } public FrmMain() { InitializeComponent(); AssemblyInfo ainfo = new AssemblyInfo(); this.Text = "Tuse HIPOT Operator Interface " + ainfo.Version; } public void CommWith3153At9600() { strTestResult = null; try { //Open Port _serialPort.Open(); _serialPort.ReadTimeout = 5000; //Send Clear command in case of unexpected behaviours. _serialPort.WriteLine("*cls"); _serialPort.WriteLine(CRLF); //Send Start Command&Read _serialPort.WriteLine("start"); _serialPort.WriteLine(CRLF); //Read Status _ESR0CommandSent = true; while (_ESR0CommandSent == true) { char ch = ' '; while ((ch == '0') || (ch == ' ')) { _serialPort.WriteLine("ESR0?"); _serialPort.WriteLine(CRLF); //character, carriage return is ascii:13 and Line feed is ascii 10 string message = _serialPort.ReadLine(); if (message.StartsWith("9")) //Test completed and within limits of comparator (PASS) { ch = '9'; strTestResult = "Passed"; _ESR0CommandSent = false; } else if (message.StartsWith("10")) //Test completed and above upper of comparator (FAIL) { ch = 'A'; strTestResult = "Above Failed"; _ESR0CommandSent = false; } else if (message.StartsWith("12")) //Test completed and below lower limit of comparator (FAIL) { ch = 'C'; strTestResult = "Lower Failed"; _ESR0CommandSent = false; } } // while ((ch == '0') || (ch == ' ')) }//while if (strTestResult != "Passed") { _ESR0CommandSent = false; } //if //Print Result to The Status Bar statusBar1.Text = "Result: " + strTestResult; } catch (Exception) { MessageBox.Show("Cannot communicate with the device"); ParallelPort.HipotParPort.HipotParPort1(false); System.Environment.Exit(-1); } } //CommWith3153At9600 public void RunTest() { button_Run.Enabled = false; lblDut1.BackColor = SystemColors.Window; lblDut1.Update(); statusBar1.Text = ""; lblDut1.Text = ""; strTestResult = null; CommWith3153At9600(); if (strTestResult == "Passed") // { lblDut1.BackColor = Color.GreenYellow; } //if else { lblDut1.BackColor = Color.Red; lblDut1.Text = "Failed"; //make the bulb on to warn the operator that test has failed. ParallelPort.HipotParPort.HipotParPort1(true); statusBar1.Text = "HIPOT TEST FAILED"; MessageBox.Show("HIPOT TEST FAILED!!!", "Hipot Test Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); //send stop command to the hipot and close serial connection _serialPort.WriteLine("stop"); _serialPort.WriteLine(CRLF); _serialPort.WriteLine("*cls"); _serialPort.WriteLine(CRLF); _serialPort.Close(); //make the bulb off ParallelPort.HipotParPort.HipotParPort1(false); goto result1; } //else _serialPort.WriteLine("*cls"); _serialPort.WriteLine(CRLF); _serialPort.Close(); strTestResult = null; result1: button_Run.Enabled = true; button_Run.Text = "RUN"; button_Run.Update(); } //public void RunTest() private void button_Run_Click_1(object sender, EventArgs e) { RunTest(); } //button_Run_Click } // public partial class FrmMain : Form } The Parallel Port Code
The code in Parallelport.cs file was modified from the using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Text; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; namespace ParallelPort { public partial class HipotParPort : Form { public static int nAddress = 888; //Default is LPT1. If you want to use LPT2 choose 632 public static Int32 onValue = 1; //decimal 1 -> only D0 is high. public static Int32 offValue = 0; //decimal 0 -> all data pins of the ParallelPort is low. public static int nDelay = 1000; // put some time between ON/OFF states in case of burning... public class PortAccess { //http://logix4u.net/Legacy_Ports/Parallel_Port/Inpout32.dll_for_Windows_98/2000/NT/XP.html //Check the upper url to learn how the inpout32.dll works //Note that inpout32.dll must be put to the C:\Windows\System32 folder. [DllImport("inpout32.dll", EntryPoint="Out32")] public static extern void Output(int nAddress, int nDecimalValue); } //public class PortAccess public static void HipotParPort1(Boolean bBulbOn) { Application.DoEvents(); if (bBulbOn) PortAccess.Output(nAddress, onValue); else PortAccess.Output(nAddress, offValue); Thread.Sleep(nDelay); } private void InitializeComponent() { this.SuspendLayout(); // // HipotParPort // this.ClientSize = new System.Drawing.Size(104, 47); this.Name = "HipotParPort"; this.ResumeLayout(false); } //public static void HipotParPort1(Boolean bBulbOn) } } How to Use the HIPOT ProgramHipot Interface program is used for controlling HIOKI HIPOT test devices.
![]()
You must click the run button to start testing. HIOKI 3153 Automatic Insulation Resistance Withstanding Tester Settings
1) Default connection settings of 3153 Hipot tester
2) Program arrange mode of the Hipot tester as in the following initial settings; Note that, these settings obtained by trying the device manually. 3) If the result of the test is fail, then D0 pin (#2) of the parallel port gets high. But you can also set other pins to be lit.
4) If the result of the test is fail and to make the tester to hear the beep sound,then 3153 To PC Interface
The 3153 includes two 8 bit event registers. It is possible to determine the status of the unit by The event registers is cleared in these situations:
a) Standart Event Status Register (SESR) bit assignments
c) RS 232 Command Reference
Final Note
I hope you have found my project very useful and can implement other devices.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||