Mengontrol Input dan Output Paralel Port dengan C#
Pin No | SPP Signal | Direction In/out | Register.bit |
1* | nStrobe | In/Out | Control.0 |
2 | Data 0 | In/Out | Data.0 |
3 | Data 1 | In/Out | Data.1 |
4 | Data 2 | In/Out | Data.2 |
5 | Data 3 | In/Out | Data.3 |
6 | Data 4 | In/Out | Data.4 |
7 | Data 5 | In/Out | Data.5 |
8 | Data 6 | In/Out | Data.6 |
9 | Data 7 | In/Out | Data.7 |
10 | nAck | In | Status.6 |
11* | Busy | In | Status.7 |
12 | Paper-Out / Paper-End | In | Status.5 |
13 | Select | In | Status.4 |
14* | nAuto-Linefeed | In/Out | Control.1 |
15 | nError / nFault | In | Status.3 |
16 | nInitialize | In/Out | Control.2 |
17* | nSelect-Printer/ nSelect-In | In/Out | Control.3 |
18 – 25 | Ground | Gnd |
Alamat Register2 paralel port:
Register | Alamat |
Data register (Base Address + 0) | 0x378 |
Status register (Base Address + 1) | 0x379 |
Control register (Base Address + 2) | 0x37a |
Sebelum memprogram Paralel port anda harus mendowload file
inpout32.dll kemudian simpan di direktory system di windows anda.
1. Buat Project baru
2. Drag and drop 2 tombol dan 2 text box
3. buat class baru , beri nama LPT
//untuk class LPT isinya sbb:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace WindowsFormsApplication2 { class LPT { [DllImport("inpout32.dll", EntryPoint = "Out32")] public static extern void Output(int adress, int value); [DllImport("inpout32.dll", EntryPoint = "Inp32")] public static extern int Input(int adress); } }
Untuk di form utama isi code nya spt ini:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnKirimKeLPT_Click(object sender, EventArgs e) { LPT.Output(0x378, Int32.Parse(txtdataOut.Text)); } private void btnBacaLPT_Click(object sender, EventArgs e) { txtdataIn.Text = Convert.ToString(LPT.Input(0x378)); } private void Form1_Load(object sender, EventArgs e) { } } }
Posted on 14/07/2011, in Menengah-3. Bookmark the permalink. 4 Comments.
ganti alamat register data dg alamat register status.
tanya mas kalo mau membaca port status dengan C# gimana ya
pin 2 -9 bisa untuk di baca dan di tulis ,
Mw tanya gan, kalo mw baca data dr port paralel, bisa tidak di pin 2-8?