Я пытаюсь получить данные с биометрического устройства учета рабочего времени zkteco k40 при весенней загрузке.JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Я пытаюсь получить данные с биометрического устройства учета рабочего времени zkteco k40 при весенней загрузке.

Сообщение Anonymous »

Я где-то читал, что сначала нам нужно подключиться к IP-порту устройства. Я подключился через код с помощью веб-сокета. Это мой код. когда я запускаю это, я получаю исключение SocketTimedOut... Вот почему я увеличил время READ_TIMEOUT. Эта проблема все еще возникает? Что я сделал не так? Что мне следует сделать, чтобы подключиться и получить данные с БИОМЕТРИЧЕСКОГО устройства?

Код: Выделить всё

    public String getAttendanceData() {
StringBuilder response = new StringBuilder();
Socket socket = null;
DataOutputStream dataOutputStream = null;
BufferedReader reader = null;

try {
// Establish a socket connection to the device
socket = new Socket();
socket.connect(new InetSocketAddress(DEVICE_IP, DEVICE_PORT), CONNECTION_TIMEOUT);
socket.setSoTimeout(READ_TIMEOUT); // Set socket read timeout

System.out.println("Connection established to device at " + DEVICE_IP + ":" + DEVICE_PORT);

// Send authentication request with the username and password
String authCommand = "AUTH:" + USERNAME + ":" + PASSWORD;
dataOutputStream = new DataOutputStream(socket.getOutputStream());
dataOutputStream.write(authCommand.getBytes());
System.out.println("Sent authentication command to device: " + authCommand);

// Wait briefly before continuing, to ensure the device has time to process
Thread.sleep(1000);

// Read the response from the device
reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
response.append(line).append("\n");
}

System.out.println("Received response from device.");
} catch (SocketTimeoutException e) {
System.err.println("Connection timed out: " + e.getMessage());
return "Error: Connection timed out while fetching attendance data.";
} catch (SocketException e) {
System.err.println("Connection reset: " + e.getMessage());
return "Error: Connection reset. The device might have closed the connection unexpectedly.";
} catch (IOException e) {
System.err.println("I/O error while communicating with the device: " + e.getMessage());
return "Error fetching attendance data: " + e.getMessage();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
try {
if (reader != null) reader.close();
if (dataOutputStream != null) dataOutputStream.close();
if (socket != null && !socket.isClosed()) socket.close();
} catch (IOException e) {
System.err.println("Error closing resources: " + e.getMessage());
}
}

return response.toString();
}
}
Я пытаюсь получить данные о посещаемости с этого устройства

Подробнее здесь: https://stackoverflow.com/questions/793 ... rom-spring
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»