设为首页
收藏本站
027热线15007117091
 位置: 武汉软件网 >> 文章频道 >> C#资源 >> 网络摘抄 >> 正文 软件定制热线 15007117091  [2008-04-23 08:50:07]      "科能健康体检系统"完成  [2007-12-02 11:15:55]      文档镇守使最新版下载  [2007-12-02 11:13:22]      网站改版完成  [2007-12-02 11:11:40]
 
热门文章
 实力游资席位及私募持仓图...
 盘点激情床戏抢镜的10大影...
 英文三字趣味经
 14种智能化系统在医院的应...
 深入浅出 Linux命令行札记...
 十大免费服务器工具
 六大科技趋势将改变家庭健...
 53年林彪高岗密谋架空总理...
推荐文章
 实力游资席位及私募持仓图...
 盘点激情床戏抢镜的10大影...
 英文三字趣味经
 14种智能化系统在医院的应...
 深入浅出 Linux命令行札记...
 十大免费服务器工具
 六大科技趋势将改变家庭健...
 53年林彪高岗密谋架空总理...
相关文章
Controlling the 3153 Hioki Hipot Device by using Serial and Parallel Port in C#
[ 作者:Admin     来源:武汉软件网     点击数:7174     更新时间:2007-12-13     文章录入:Admin

Introduction

Serial port (RS-232) is still used in industrial applications but it has recently disappeared from most of the notebooks.
There is a SerialPort class in the .NET Framework and you can use this class 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.

In the end of this page, 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.

The Namespace

I use two different namespace. One of them is hipotinterface which includes main program and serial port codes.
The other one is ParallelPort namespace that contains Parallel port issues.

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.

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.

Collapse
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            {                //Browse all available ports, if necessary;                //string[] strARAvailablePorts = SerialPort.GetPortNames();                //Open Port                _serialPort.Open();                _serialPort.ReadTimeout = 5000;                //Send any Character To Pass 3153 to Remote Mode.                _serialPort.WriteLine("\r\n");                //Set Withstand Test-voltage type to :AC 50 Hz                _serialPort.WriteLine("conf:with:kind AC50");                _serialPort.WriteLine("\r\n");                //Set Withstand Test Voltage to 3.00kV                _serialPort.WriteLine("conf:with:volt 3.00");                _serialPort.WriteLine("\r\n");                //Set Withstand Cutoff current upper limit to 5.5 mA                _serialPort.WriteLine("with:clow ON");                _serialPort.WriteLine("\r\n");                _serialPort.WriteLine("conf:with:cupp 5.5");                _serialPort.WriteLine("\r\n");                //Set Withstand Cutoff current lower limit to 0.7 mA                _serialPort.WriteLine("conf:with:clow 0.7");                _serialPort.WriteLine("\r\n");                //Set Withstand Ramp Timer(Test Time) to :3.0 s.                _serialPort.WriteLine("with:tim ON");                _serialPort.WriteLine("\r\n");                _serialPort.WriteLine("conf:with:tim 3.0");                _serialPort.WriteLine("\r\n");                //Set Withstand Ramp-up Timer to OFF                _serialPort.WriteLine("with:utim OFF");                _serialPort.WriteLine("\r\n");                //Set Withstand Ramp-down Timer to OFF                _serialPort.WriteLine("with:dtim OFF");                _serialPort.WriteLine("\r\n");                ////                //Set Insulation Test-voltage type to :DC                _serialPort.WriteLine("conf:ins:kind AC50");                _serialPort.WriteLine("\r\n");                //Set Insulation Test Voltage to 500V                _serialPort.WriteLine("conf:ins:volt 500");                _serialPort.WriteLine("\r\n");                //Set Insulation Resistance upper limit to :OFF.                _serialPort.WriteLine("ins:rupp OFF");                _serialPort.WriteLine("\r\n");                //Set Insulation Resistance lower limit to : 4.0 Mohm                _serialPort.WriteLine("conf:ins:rlow 4.0");                _serialPort.WriteLine("\r\n");                //Set Insulation Test Time to :1.0 s.                _serialPort.WriteLine("ins:tim ON");                _serialPort.WriteLine("\r\n");                _serialPort.WriteLine("conf:ins:tim 1.0");                _serialPort.WriteLine("\r\n");                //Set Insulation delay time to OFF.                _serialPort.WriteLine("ins:del OFF");                _serialPort.WriteLine("\r\n");                ////                //Set Test Mode: Withstand voltage mode -> insulation resistance mode                _serialPort.WriteLine(":mode AWI");                _serialPort.WriteLine("\r\n");                _serialPort.Close();            }            catch (Exception)            {                MessageBox.Show("Initialization Error.\nCheck the connection!", "Hipot Default Settings Error");                Application.Restart();            }                   }       public FrmMain()       {            InitializeComponent();            AssemblyInfo ainfo = new AssemblyInfo();            this.Text = "Tuse HIPOT Operator Interface " + ainfo.Version;       }       private void button_Run_Click(object sender, EventArgs e)        {            RunTest();        } //button_Run_Click       public void CommWith3153At9600()        {                        strTestResult = null;            try            {                //_serialPort = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);                //Open Port                _serialPort.Open();                _serialPort.ReadTimeout = 5000;                //OBSOLOTE                //Send any Character To Pass 3153 to Remote Mode.                //_serialPort.WriteLine("\r\n");                //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")                {                    /*_serialPort.WriteLine("stop");                    _serialPort.WriteLine(CRLF);                    _serialPort.WriteLine("*cls");                    _serialPort.WriteLine(CRLF);*/                    _ESR0CommandSent = false;                    //_serialPort.Close();                } //if                  //Close Port                //_serialPort.Close();                 //Print Result to The Status Bar                statusBar1.Text = "Result: " + strTestResult;            }            catch (Exception)            {                MessageBox.Show("Cannot communicate with the device.", "Communication Error");                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()           }   // 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. The code assumes LPT1 is as
the default parallel port and lights only the first pin (D0) when the test fails.

Collapse
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.
Beside that, top cover must be closed for the operator safety.
If you run the program, you see the following screeen;

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 HiTester
a) Serial Port: "COM1"
b) Bps: 9600
c) Parity :1
d) Databits :8
e) StopBits :1

2) Program arrange mode of the HiTester 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

3) If the result of the test is fail, then D0 pin (#2) of the parallel port gets high.

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 HiTester. 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:
i. When a “*cls” command is executed
ii. When the event register is executed
iii. 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 comman 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 dadta 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 0: Unused

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
Example:
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 comoarator (FAIL)
3) ESR0 = xxxx1001 = 0x09 = .9 ------à Teswt 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 contens of the standartbevent 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
anumerical value in NR1
format between 0 to 255 and then clears the ESR0 register

Final Note

I hope you find my project very useful and can implement other devices. I tried to avoid classical
putting all the available serial port options to a combo box and something like that. 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.

<-- Article Ends --><-- Main Page Contents End -->
发表评论   告诉好友   打印此文  收藏此页  关闭窗口  返回顶部
  • 上一篇文章: Mobile Application Development Best Practices

  • 下一篇文章: C# 实现Windows Media Encoder音视频捕捉
  • ∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!)
     
     

    Copyright© 2001-2007 ICP备案号:鄂ICP备05027628号
    027-soft.com 武汉软件定制
    本站为武汉城市圈内企业提供管理软件开发,软件策划等服务
    发表、收集一些企业E化的实例及其经验等的资料与大家共享。
    希望大家多提意见,同时共同进步。

    | 页面执行时:0.143 毫秒