使用插座处理生物指纹考勤机 [英] Handling a Biometric Fingerprint Attendance Device by using socket

查看:79
本文介绍了使用插座处理生物指纹考勤机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Java程序与生物特征指纹考勤设备连接.我使用的设备是Biocom指纹考勤系统.但是,我正在搜索和阅读有关此内容,并且看到该SDK可以根据设备类型使用它(哪个是硬的,不是逻辑的,而且这不是全局解决方案!)

I am trying to connect with a Biometric Fingerprint Attendance Device using a Java program. The device I am using is a Biocom Fingerprint attendance system. However, I am search and reading about that and I see the SDK could used which based on device type (which hard, not logical, moreover, it is not global solution!)

我研究了有关如何使用指纹设备进行连接,发送和检索数据的全球标准,但我再次没有足够的幸运找到一个清晰的解决方案.目前,我尝试通过创建Socket对象(通过以太网端口)与设备连接,但未与我一起执行.这种开放式无限循环问题困扰着我.

I research for a global standard on how to connect, send and retrieve data with a Fingerprint Device which again I wasn't lucky enough to find a clear solution. Currently, I tried to connect with the device by creating a Socket object (through Ethernet port) but also not executed with me. This open infinite loop problems on my head.

  • 是否存在使用Java从此类设备连接,发送和检索数据的通用,标准方法?
  • 可以将Socket视为解决此问题的方法吗?
  • 如果是,下面我的代码有什么问题?连接设备需要除主机IP和端口号之外的其他功能?
  • Is there any general, standard way to connect, send and retrieve data from such device using Java?
  • Can a Socket be considered as a solution for such problem?
  • If yes, what is wrong in my code below? What additional things more than the host IP and port number are needed to connect with the device?

使用的套接字代码:

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class Requester {
Socket requestSocket;
ObjectOutputStream out;
ObjectInputStream in;
String message;

Requester() {
}

void run() throws IOException {
    try {
        // 1. creating a socket to connect to the server
        requestSocket = new Socket("192.168.0.19", 4370);
        System.out.println("Connected to given host in port 4370");
        // 2. get Input and Output streams
        in = new ObjectInputStream(requestSocket.getInputStream());
        // 3: Communicating with the server
        String line;
        while (true) {
            line = in.readLine();
            if (line != null) {
                System.out.println(line);
            }
        }
    } catch (UnknownHostException unknownHost) {
        System.err.println("You are trying to connect to an unknown host!");

    } catch (IOException ioException) {
        ioException.printStackTrace();

    } catch (Exception Exception) {
        Exception.printStackTrace();

    } finally {
        in.close();
        requestSocket.close();
    }
}

void sendMessage(String msg) {
    try {
        out.writeObject(msg);
        out.flush();
        System.out.println("client: " + msg);

    } catch (IOException ioException) {
        ioException.printStackTrace();
    }
}

public static void main(String args[]) throws IOException {
    Requester client = new Requester();
    client.run();
}
}

此图片可能会提供更多详细信息:

This image may give more details:

推荐答案

您不需要ObjectInputStream.只需使用从requestSocket.getInputStream()获得的InputStream.

You don't need the ObjectInputStream. Just use the InputStream you get from requestSocket.getInputStream().

或者使用腻子之类的终端程序连接到您的设备.这不需要编码.

Alternatively use a terminal programm like putty to connect to your device. This requires no coding.

这篇关于使用插座处理生物指纹考勤机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆