Skip to content

Commit

Permalink
jos
Browse files Browse the repository at this point in the history
  • Loading branch information
udibagas committed Sep 9, 2019
1 parent fc2e016 commit f8fc5e6
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 85 deletions.
12 changes: 12 additions & 0 deletions gate.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[api]
url = http://192.168.1.6/api

[host]
address = 192.168.1.13

[cmd]
open = AZ123
close =

[log]
file = gate.log
67 changes: 31 additions & 36 deletions gate_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
import logging
import os
import sys
import configparser

API_URL = 'http://192.168.1.6/api'
IP_ADDRESS = '192.168.1.13'
GATE_CMD_OPEN = b'AZ123'
GATE_CMD_CLOSE = None
CFG = configparser.ConfigParser()
CFG.read_file(open(os.path.join(os.path.dirname(__file__), 'gate.cfg')))

log_file = os.path.join(os.path.dirname(__file__), "gate.log")
log_file = os.path.join(os.path.dirname(__file__), CFG['log']['file'])
logging.basicConfig(filename=log_file, filemode='a', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')

try:
r = requests.get(API_URL + '/parkingGate/search', params={ 'controller_ip_address': IP_ADDRESS }, timeout=3)
r = requests.get(CFG['api']['url'] + '/parkingGate/search', params={ 'controller_ip_address': CFG['host']['address'] }, timeout=3)
except Exception as e:
logging.error('Failed to get gate. Quit program.' + str(e))
logging.error('Failed to get gate. Quit program. ' + str(e))
sys.exit()

gate = r.json()[0]
Expand All @@ -35,34 +34,30 @@
logging.info('Connected by ' + str(addr))

with conn:
while True:
data = conn.recv(1024)
if not data:
data = conn.recv(1024)
logging.debug('Command : ' + str(data))

if data == b'OPEN':
try:
ser = Serial(gate['controller_device'], int(gate['controller_baudrate']), timeout=1)
except Exception as e:
conn.sendall(b'Failed to open serial')
logging.error('Failed to open serial. ' + str(e))
break

logging.debug('Command : ' + str(data))

if data == b'OPEN':
try:
ser = Serial(gate['controller_device'], int(gate['controller_baudrate']), timeout=1)
except Exception as e:
conn.sendall(b'Failed to open serial')
logging.error('Failed to open serial. Permission error.' + str(e))
break

try:
ser.write(GATE_CMD_OPEN)

if GATE_CMD_CLOSE is not None:
time.sleep(1)
ser.write(GATE_CMD_CLOSE)

ser.close()
conn.sendall(b'OK')
logging.info("Gate opened")
except Exception as e:
logging.error(str(e))
conn.sendall(b'GATE GAGAL DIBUKA')
else:
conn.sendall(b'Invalid command')
logging.error('Invalid command')
try:
ser.write(CFG['cmd']['open'].encode())

if CFG['cmd']['close'] is not None:
time.sleep(1)
ser.write(CFG['cmd']['close'].encode())

ser.close()
conn.sendall(b'OK')
logging.info("Gate opened")
except Exception as e:
logging.error(str(e))
conn.sendall(b'GATE GAGAL DIBUKA')
else:
conn.sendall(b'Invalid command')
logging.error('Invalid command')
87 changes: 39 additions & 48 deletions resources/js/pages/GateOutApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,7 @@

<el-row :gutter="10" style="margin-bottom:10px;">
<el-col :span="10">
<div class="label-big">[.] NO. KARTU</div>
</el-col>
<el-col :span="14">
<input id="card-number" autocomplete="off" @keyup.enter="checkCard" type="text" placeholder="NO. KARTU" v-model="formModel.card_number" class="my-input">
</el-col>
</el-row>

<el-row :gutter="10" style="margin-bottom:10px;">
<el-col :span="10">
<div class="label-big">[+] NO. TIKET</div>
<div class="label-big">[+] NO. TIKET/KARTU</div>
</el-col>
<el-col :span="14">
<input id="ticket-number" maxlength="5" autocomplete="off" @keyup.enter="checkTicket" type="text" placeholder="NO. TIKET" v-model="formModel.barcode_number" class="my-input">
Expand Down Expand Up @@ -169,44 +160,44 @@ export default {
})
}
},
checkCard() {
if (!this.formModel.gate_out_id) {
this.$message({
message: 'MOHON PILIH GATE OUT',
type: 'error',
showClose: true,
})
return
}
let now = moment().format('YYYY-MM-DD HH:mm:ss')
let params = { card_number: this.formModel.card_number, gate_in_id: this.formModel.gate_out_id }
axios.get('/parkingTransaction/search', { params: params }).then(r => {
this.formModel.id = r.data.id
this.formModel.gate_in_id = r.data.gate_in_id
this.formModel.barcode_number = r.data.barcode_number
this.formModel.vehicle_type = r.data.vehicle_type
this.formModel.time_in = r.data.time_in
this.formModel.time_out = now
this.formModel.fare = 0
this.snapshot_in = r.data.snapshot_in
this.setDuration()
this.$forceUpdate()
this.takeSnapshot(r.data.id)
// langsung update & buka gate. gak perlu print tiket
setTimeout(() => {
this.update()
this.openGate()
}, 1000)
document.getElementById('vehicle-type').focus()
}).catch(e => {
this.$message({
message: e.response.data.message,
type: 'error',
showClose: true,
})
})
},
// checkCard() {
// if (!this.formModel.gate_out_id) {
// this.$message({
// message: 'MOHON PILIH GATE OUT',
// type: 'error',
// showClose: true,
// })
// return
// }
// let now = moment().format('YYYY-MM-DD HH:mm:ss')
// let params = { card_number: this.formModel.card_number, gate_in_id: this.formModel.gate_out_id }
// axios.get('/parkingTransaction/search', { params: params }).then(r => {
// this.formModel.id = r.data.id
// this.formModel.gate_in_id = r.data.gate_in_id
// this.formModel.barcode_number = r.data.barcode_number
// this.formModel.vehicle_type = r.data.vehicle_type
// this.formModel.time_in = r.data.time_in
// this.formModel.time_out = now
// this.formModel.fare = 0
// this.snapshot_in = r.data.snapshot_in
// this.setDuration()
// this.$forceUpdate()
// this.takeSnapshot(r.data.id)
// // langsung update & buka gate. gak perlu print tiket
// setTimeout(() => {
// this.update()
// this.openGate()
// }, 1000)
// document.getElementById('vehicle-type').focus()
// }).catch(e => {
// this.$message({
// message: e.response.data.message,
// type: 'error',
// showClose: true,
// })
// })
// },
checkPlate(e) {
if (!this.formModel.plate_number) {
return
Expand Down
2 changes: 1 addition & 1 deletion test_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

command = [
'\xa6PR4', # start print command, baudrate 9600
'\x1b\x61\x01TIKET PARKIR\n',
'\x1b\x61\x01TIKET PARKIR\n', # align center
'\x1b\x21\x10MITRATEKNIK\n\n', # double height
'\x1b\x21\x00', # normal height
'\x1b\x61\x00', # align left
Expand Down

0 comments on commit f8fc5e6

Please sign in to comment.