5,446,542 members and growing! (18,679 online)
Email Password   helpLost your password?
Languages » C# » General     Intermediate License: The GNU General Public License (GPL)

Controlling A Real Measurement "3153 Hioki Hipot" Device by using Serial and Parallel Port in C#

By Serhat

Controlling the 3153 Hioki Hipot Device by using Serial and Parallel Port in C#
C# (C# 1.0, C# 2.0, C# 3.0, C#)

Posted: 11 Dec 2007
Updated: 2 Feb 2008
Views: 8,133
Bookmarked: 23 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
3 votes for this Article.
Popularity: 1.64 Rating: 3.43 out of 5
0 votes, 0.0%
1
1 vote, 33.3%
2
0 votes, 0.0%
3
2 votes, 66.7%
4
0 votes, 0.0%
5
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.
There is a SerialPort class in the .NET Framework to handle all serial port communication and you can use this class in your code simply by adding “using System.IO.Ports;”. Also,
for parallel port access you must use Inpout32.dll from the following URL;

http://logix4u.net/Legacy_Ports/Parallel_Port/Inpout32.dll_for_Windows_98/2000/NT/XP.html

In this project, I use a real device to communicate by using Hioki 3153 Hipot tester via serial port.Indication of the fail
condition will be shown by the LED as told in the article:

I/O Ports Uncensored - 1 - Controlling LEDs (Light Emiting Diodes) with Parallel Port by Levent Saltuklaroglu.

At the end of this article, you can get information about the Hipot device. All the information are taken from the manual of the device.
Thanks to Behlul Savaskan for typing of these parts. Also I must mention that Hioki may not have a Customer Support Department.
I asked some questions via e-mail, but I did not get any reply from them. Finally, I also add an Setup project for the copying
inpout32.dll which is needed for the parallel port to the C:\Windows\System32 folder.

The Namespace

I use two different namespaces. One of them is hipotinterface which includes main program and serial port codes.
The other one is ParallelPort namespace that handles parallel port communication.

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
pins set to low and the device is set with the settings indicated in
HIOKI 3153 Automatic Insulation Resistance Withstanding Tester Settings section of this document. According to the user manual, after every command a delimiter
(Carriage Return and Line Feed) must be used. I used Writeline method of the SerialPort class.
The settings like "conf:with:kind AC50" are taken from user manual. I used FrmMain_Load event to force the device to be started
with my initial settings in case of changing of the parameters by the operator.

In the CommWith3153At9600 function, Hipot device communicates with our PC. You can read the 3153 To PC Interface section
for the details of sent messages and queries.

The RunTest() function handles Red/Green label transformation, closing serial and parallel ports according to result
of the CommWith3153At9600 function.

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
I/O Ports Uncensored - 1 - Controlling LEDs (Light Emiting Diodes) with Parallel Port by Levent Saltuklaroglu ,
if you need line by line information, you should take a look at this article. The code assumes that LPT1 is the default parallel port and
lights only the first pin (D0) when the test fails.

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 Program

Hipot Interface program is used for controlling HIOKI HIPOT test devices.


ATTENTION: You must remove all External I/O card, Start/Stop buttons etc. if there is any. Because,
they will not work at the remote mode. Beside that, top cover must be closed for the operator safety.
I asked to the Hioki the usage of this top cover at the remote mode, unfortunately I did not get any response.
If you run the program, you see the following screen;

You must click the run button to start testing.
If the DUT (Device Under Test) passed the testing, there will be green bar on the form. Otherwise,
you will see Red bar to indicate that test has failed and a pop-up message.

HIOKI 3153 Automatic Insulation Resistance Withstanding Tester Settings

1) Default connection settings of 3153 Hipot tester
a) Serial Port: "COM1"
b) Bps: 9600
c) Parity :1
d) Databits :8
e) StopBits :1

2) Program arrange mode of the Hipot tester as in the following initial settings;
//Send any Character To Pass 3153 to Remote Mode.
//Set Withstand Test-voltage type to :AC 50 Hz
//Set Withstand Test Voltage to 3.00kV
//Set Withstand Cutoff current upper limit to 5.5 mA
//Set Withstand Cutoff current lower limit to 0.7 mA
//Set Withstand Ramp Timer(Test Time) to :3.0 s.
//Set Withstand Ramp-up Timer to OFF
//Set Withstand Ramp-down Timer to OFF
//Set Insulation Test-voltage type to :DC
//Set Insulation Test Voltage to 500V
//Set Insulation Resistance upper limit to :OFF.
//Set Insulation Resistance lower limit to : 4.0 Mohm
//Set Insulation Test Time to :1.0 s.
//Set Insulation delay time to OFF.
//Set Test Mode: Withstand voltage mode -> insulation resistance mode

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
stop command will not send to the Hipot tester. To stop it, the operator has to click the
OK button.

3153 To PC Interface

The 3153 includes two 8 bit event registers. It is possible to determine the status of the unit by
reading these registers.

The event registers is cleared in these situations:

  1. When a “*cls” command is executed
  2. When the event register is executed
  3. When the unit is powered on

a) Standart Event Status Register (SESR) bit assignments

Bit 7

PON

Power On Flag

When the power is turned on or on recovery from a power cut, this bit is set to 1

Bit 6 Unused
Bit 5 CME

Command Error

When a command which has been received contains a syntactic or semantic error, this bit is set to 1

  • The command is not supported by the 3153
  • There is a mistake in a program header
  • The number of data parameters is wrong
  • The format of parameters is wrong
Bit 4 EXE

Execution Error

When some reason a command which has been received cannot be executed, this bit is set to 1

  • The designated data value is outside the set range
  • The designated data value is not acceptable
Bit 3 DDE

Device dependent error

When a command cannot be executed due to some cause other than a command error ,a query error or an execution error, this bit is set to 1

Bit 2 QYE

Query error

This bit is set to 1 when a query error detected by the output queue control

  • When the data overflows the output queue
  • When data in output queue has been lost
Bit 1 Unused
Bit 0Unused








































b) Event Status Register 0 (ESR0) bit assignments

Bit 7 Unused
Bit 6 Unused
Bit 5 Unused
Bit 4 Unused

Bit 3

EOM
Test completed

Bit 2

LFAIL

Below lower limit of comparator

Bit 1

UFAIL

Above upper limit of comparator

Bit 0

PASS

Within limits of comparator























  1. ESR0 = xxxx1100 = 0x0C = .12 ----> Test completed and below lower limit of comparator (FAIL)
  2. ESR0 = xxxx1010 = 0x0A = .10 ----> Test completed and above upper of comparator (FAIL)
  3. ESR0 = xxxx1001 = 0x09 = .9 -----> Test completed and within limits of comparator (PASS)

c) RS 232 Command Reference

  • CLS -----> Clears the status byte registers and the event registers
  • ESR? -----> Returns the contents of the Standart Event Status Register (SESR) as a numerical
    value in NR1 format between 0 to 255 and then clears the SESR register
  • ESR0? -----> Returns the value of event status register 0 (ESR0) as a numerical value in NR1 format
    between 0 to 255 and then clears the ESR0 register

Final Note

I hope you have found my project very useful and can implement other devices.
I try to avoid classical putting all the available serial port options to a combo box approach coding.
By examining the 3153 To PC interface section and my code, you can understand how things can be implemented.
Also, please excuse me for my English.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPL)

About the Author

Serhat


I worked as a Senior Test Development Engineer in the major consumer electronics company of Turkey. I had some experience on DVB, Wireless TV, Debian GNU/linux, National Instruments products (Teststand, measurement studio, Labview) and Embedded systems (mostly Single Board Computers).

Currently, I work as a design engineer in the Aerospace/Defence Industry.
Location: Turkey Turkey

Other popular C# articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Search Search Messages 
 Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralDownload linkli çalışmıyormemberMuhammed Sahin23:28 21 Jan '08  
GeneralRe: Download linkli çalışmıyormemberSerhat1:56 22 Jan '08  
GeneralRe: Download linkli çalışmıyormemberMuhammed Sahin2:31 22 Jan '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 2 Feb 2008
Editor:
Copyright 2007 by Serhat
Everything else Copyright © CodeProject, 1999-2008
Web19 | Advertise on the Code Project