Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana membuat sebuah alat untuk menghitung jumlah barang sekaligus melihat kode barcodenya, selain itu juga memunculkan informasi terkait barang tersebut pada interface vb 6 dengan database yang digunakan adalah MS ACCESS, jadi alat ini yang pertama akan men-scan barcode kemudian akan menghitung jumlah barang, kemudian akan mengirimkan kode barcode tersebut ke interface vb 6, pada interface vb 6 akan ditamplkan beberapa informasi seperti nama barang, tanggal produksi, tanggal kadaluarsa dan kode barcodenya, pada interface juga dilengkapi dengan beberapa buah tombol untuk insert data secara manual ke database jika data di database tidak mencantumkan kode barcode yang baru. alat ini menggunakan arduino sebagai kontrollernya dan Barcode scanner MCR 12 sebagai reader ITF 14 code nya, untuk lebih jelasnya berikut adalah skema dan programnya.
Link Download Program
https://www.4shared.com/rar/T3nkpMkAca/barcode.html
a. Arduino Mega
b. Barcode Scanner MCR 12
c. LCD 16x2
d. Program Arduino IDE
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, 12, 4, 5, 6, 7);
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
String barcode;
int jumlah = 0;
void setup() {
lcd.begin(16, 2);
lcd.clear();
lcd.noCursor();
pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
pinMode(10,OUTPUT);
Serial.begin(9600);
inputString.reserve(200);
}
void loop() {
digitalWrite(8,HIGH);
digitalWrite(10,LOW);
analogWrite(9,50);
lcd.setCursor(0, 0);
lcd.print("JUMLAH= ");
lcd.print(jumlah);
if (stringComplete) {
//Serial.println(inputString);
barcode = inputString.substring(0,14);
lcd.setCursor(0, 1);
lcd.print(barcode);
delay(1000);
Serial.println(barcode);
lcd.setCursor(0, 1);
lcd.print(" ");
jumlah++;
inputString = "";
stringComplete = false;
}
}
void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\n') {
stringComplete = true;
}
}
}
e. Program Interface VB 6
//============= main form =========================
Dim Conn1 As ADODB.Connection
Dim Cmd1 As ADODB.Command
Dim Param1 As ADODB.Parameter
Dim Rs1 As ADODB.Recordset
Private Sub cbdelete_Click()
Dim SQl As String
Call dbConnect
SQl = "DELETE FROM Table1 WHERE Kode = '" & tbcode.Text & "'"
Dim Rs As Recordset
Set Rs = New ADODB.Recordset
Rs.Open SQl, Conn, adOpenDynamic, adLockOptimistic
tbnama.Text = ""
tbproduksi.Text = ""
tbkadaluarsa.Text = ""
tbcode.Text = ""
End Sub
Private Sub cbinsert_Click()
Dim SQl As String
Call dbConnect
SQl = "INSERT INTO Table1 VALUES('" & tbcode.Text & "','" & tbproduksi.Text & "','" & tbkadaluarsa.Text & "','" & tbnama.Text & "')"
Dim Rs As Recordset
Set Rs = New ADODB.Recordset
Rs.Open SQl, Conn, adOpenDynamic
tbcode.Text = ""
tbproduksi.Text = ""
tbkadaluarsa.Text = ""
tbnama.Text = ""
End Sub
Private Sub cbselect_Click()
Dim SQl As String
Call dbConnect
SQl = "Select * from Table1 where Kode = '" & tbcode.Text & "'"
Dim Rs As Recordset
Set Rs = New ADODB.Recordset
Rs.Open SQl, Conn, adOpenDynamic, adLockOptimistic
If Not Rs.EOF Then
tbproduksi.Text = Rs!Produksi
tbkadaluarsa.Text = Rs!Kadaluarsa
tbnama.Text = Rs!Nama
End If
End Sub
Private Sub cmdConnect_Click()
Dim port As Integer
On Error GoTo errcode
If MSComm1.PortOpen = False Then
MSComm1.CommPort = Combo1.ListIndex + 1
MSComm1.RThreshold = 1
MSComm1.InputLen = 0
MSComm1.Settings = Combo2.List(Combo2.ListIndex) & ",N,8,1"
MSComm1.PortOpen = True
cmdConnect.Enabled = False
cmdDisconnect.Enabled = True
End If
Exit Sub
errcode:
MsgBox "Port Salah !", vbOKOnly, "Peringatan"
Combo1.SetFocus
End Sub
Private Sub cmdDisconnect_Click()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
cmdConnect.Enabled = True
cmdDisconnect.Enabled = False
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim i As Byte
For i = 1 To 16
Combo1.AddItem (i)
Next i
With Combo2
.AddItem "2400"
.AddItem "4800"
.AddItem "9600"
.AddItem "19200"
.AddItem "38400"
.AddItem "56600"
End With
Timer2.Enabled = False
cmdConnect.Enabled = True
cmdDisconnect.Enabled = False
End Sub
Private Sub Timer1_Timer()
Adodc2.Refresh
End Sub
Private Sub Timer2_Timer()
MSComm1_OnComm
End Sub
Private Sub Timer3_Timer()
Dim data As String
Dim buffer As String
If MSComm1.InBufferCount > 0 Then
tbnama.Text = ""
tbproduksi.Text = ""
tbkadaluarsa.Text = ""
tbcode.Text = ""
buffer = MSComm1.Input
data = Mid$(buffer, 1, 14)
tbcode.Text = data
End If
End Sub
Private Sub Timer4_Timer()
Dim SQl As String
Call dbConnect
SQl = "Select * from Table1 where Kode = '" & tbcode.Text & "'"
Dim Rs As Recordset
Set Rs = New ADODB.Recordset
Rs.Open SQl, Conn, adOpenDynamic, adLockOptimistic
If Not Rs.EOF Then
tbproduksi.Text = Rs!Produksi
tbkadaluarsa.Text = Rs!Kadaluarsa
tbnama.Text = Rs!Nama
End If
End Sub
//=============== modul1 ======================
Public Conn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public SQl As String
Public i As Byte
Public Sub dbConnect()
Set Conn = New ADODB.Connection
Conn.ConnectionString = strConn
Conn.Open
End Sub
Public Function strConn() As String
Set Conn = New ADODB.Connection
Set Rs = New ADODB.Recordset
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\yanuar\Desktop\Projek Mei -juni 2017 & PID\barcode\interface\Database1.mdb;Persist Security Info=False"
End Function
f. VIDEO HASILNYA
No comments:
Post a Comment